Fixed placement teleporter crash, invalid packet handling
This commit is contained in:
@@ -121,7 +121,7 @@ public class Logic extends Module {
|
||||
|
||||
if(world.getCore() != null && world.getCore().block() != ProductionBlocks.core && !state.gameOver){
|
||||
state.gameOver = true;
|
||||
NetEvents.handleGameOver();
|
||||
if(Net.server()) NetEvents.handleGameOver();
|
||||
Events.fire(GameOverEvent.class);
|
||||
}
|
||||
|
||||
|
||||
@@ -170,6 +170,11 @@ public class NetClient extends Module {
|
||||
|
||||
Net.handleClient(PlacePacket.class, (packet) -> {
|
||||
Placement.placeBlock(packet.x, packet.y, Block.getByID(packet.block), packet.rotation, true, false);
|
||||
|
||||
if(packet.playerid == player.id){
|
||||
Tile tile = world.tile(packet.x, packet.y);
|
||||
if(tile != null) Block.getByID(packet.block).placed(tile);
|
||||
}
|
||||
});
|
||||
|
||||
Net.handleClient(BreakPacket.class, (packet) -> {
|
||||
|
||||
@@ -115,10 +115,11 @@ public abstract class InputHandler extends InputAdapter{
|
||||
}
|
||||
|
||||
public void placeBlock(int x, int y, Block result, int rotation, boolean effects, boolean sound){
|
||||
if(!Net.client()) Placement.placeBlock(x, y, result, rotation, effects, sound);
|
||||
|
||||
Tile tile = world.tile(x, y);
|
||||
if(tile != null) result.placed(tile);
|
||||
if(!Net.client()){
|
||||
Placement.placeBlock(x, y, result, rotation, effects, sound);
|
||||
Tile tile = world.tile(x, y);
|
||||
if(tile != null) result.placed(tile);
|
||||
}
|
||||
|
||||
if(Net.active()){
|
||||
NetEvents.handlePlace(x, y, result, rotation);
|
||||
|
||||
@@ -27,14 +27,7 @@ public class Placement {
|
||||
if(tile == null) return;
|
||||
|
||||
Block block = tile.isLinked() ? tile.getLinked().block() : tile.block();
|
||||
Recipe result = null;
|
||||
|
||||
for(Recipe recipe : Recipes.all()){
|
||||
if(recipe.result == block){
|
||||
result = recipe;
|
||||
break;
|
||||
}
|
||||
}
|
||||
Recipe result = Recipes.getByResult(block);
|
||||
|
||||
if(result != null){
|
||||
for(ItemStack stack : result.requirements){
|
||||
@@ -100,6 +93,12 @@ public class Placement {
|
||||
}
|
||||
}
|
||||
|
||||
Recipe recipe = Recipes.getByResult(type);
|
||||
|
||||
if(recipe == null || !state.inventory.hasItems(recipe.requirements)){
|
||||
return false;
|
||||
}
|
||||
|
||||
rect.setSize(type.width * tilesize, type.height * tilesize);
|
||||
Vector2 offset = type.getPlaceOffset();
|
||||
rect.setCenter(offset.x + x * tilesize, offset.y + y * tilesize);
|
||||
|
||||
Reference in New Issue
Block a user