use of com.minecolonies.coremod.tileentities.ScarecrowTileEntity in project minecolonies by Minecolonies.
the class GuiHandler method getServerGuiElement.
@Override
public Object getServerGuiElement(final int id, final EntityPlayer player, final World world, final int x, final int y, final int z) {
final BlockPos pos = new BlockPos(x, y, z);
final ScarecrowTileEntity tileEntity = (ScarecrowTileEntity) world.getTileEntity(pos);
return new Field(tileEntity, player.inventory, world, pos);
}
use of com.minecolonies.coremod.tileentities.ScarecrowTileEntity in project minecolonies by Minecolonies.
the class GuiHandler method getClientGuiElement.
@Override
public Object getClientGuiElement(final int id, final EntityPlayer player, final World world, final int x, final int y, final int z) {
final BlockPos pos = new BlockPos(x, y, z);
final ScarecrowTileEntity tileEntity = (ScarecrowTileEntity) world.getTileEntity(pos);
return new GuiField(player.inventory, tileEntity, world, pos);
}
use of com.minecolonies.coremod.tileentities.ScarecrowTileEntity in project minecolonies by Minecolonies.
the class BuildingFarmer method syncWithColony.
/**
* Synchronize field list with colony.
*
* @param world the world the building is in.
*/
public void syncWithColony(@NotNull final World world) {
if (!farmerFields.isEmpty()) {
@NotNull final ArrayList<Field> tempFields = new ArrayList<>(farmerFields);
for (@NotNull final Field field : tempFields) {
final ScarecrowTileEntity scarecrow = (ScarecrowTileEntity) world.getTileEntity(field.getID());
if (scarecrow == null) {
farmerFields.remove(field);
if (currentField != null && currentField.getID() == field.getID()) {
currentField = null;
}
} else {
scarecrow.setName(LanguageHandler.format(COM_MINECOLONIES_COREMOD_GUI_SCARECROW_USER, getWorker().getName()));
getColony().getWorld().notifyBlockUpdate(scarecrow.getPos(), getColony().getWorld().getBlockState(scarecrow.getPos()), getColony().getWorld().getBlockState(scarecrow.getPos()), BLOCK_UPDATE_FLAG);
field.setInventoryField(scarecrow.getInventoryField());
if (currentField != null && currentField.getID() == field.getID()) {
currentField.setInventoryField(scarecrow.getInventoryField());
}
}
}
}
}
use of com.minecolonies.coremod.tileentities.ScarecrowTileEntity in project minecolonies by Minecolonies.
the class BlockHutField method onBlockPlacedBy.
@Override
public void onBlockPlacedBy(@NotNull final World worldIn, @NotNull final BlockPos pos, final IBlockState state, final EntityLivingBase placer, final ItemStack stack) {
//Only work on server side.
if (worldIn.isRemote) {
return;
}
if (placer instanceof EntityPlayer) {
@Nullable final Colony colony = ColonyManager.getColony(worldIn, pos);
if (colony != null) {
@NotNull final InventoryField inventoryField = new InventoryField();
final ScarecrowTileEntity scareCrow = (ScarecrowTileEntity) worldIn.getTileEntity(pos);
final EntityPlayer player = (EntityPlayer) placer;
if (scareCrow != null) {
scareCrow.setInventoryField(inventoryField);
colony.addNewField(scareCrow, player.inventory, pos, worldIn);
}
}
}
}
use of com.minecolonies.coremod.tileentities.ScarecrowTileEntity in project minecolonies by Minecolonies.
the class Colony method cleanUpBuildings.
private void cleanUpBuildings(@NotNull final TickEvent.WorldTickEvent event) {
@Nullable final List<AbstractBuilding> removedBuildings = new ArrayList<>();
//Need this list, we may enter he while we add a building in the real world.
final List<AbstractBuilding> tempBuildings = new ArrayList<>(buildings.values());
for (@NotNull final AbstractBuilding building : tempBuildings) {
final BlockPos loc = building.getLocation();
if (event.world.isBlockLoaded(loc) && !building.isMatchingBlock(event.world.getBlockState(loc).getBlock())) {
// Sanity cleanup
removedBuildings.add(building);
}
}
@NotNull final ArrayList<Field> tempFields = new ArrayList<>(fields.values());
for (@NotNull final Field field : tempFields) {
if (event.world.isBlockLoaded(field.getLocation())) {
final ScarecrowTileEntity scarecrow = (ScarecrowTileEntity) event.world.getTileEntity(field.getID());
if (scarecrow == null) {
fields.remove(field.getID());
} else {
field.setInventoryField(scarecrow.getInventoryField());
}
}
}
removedBuildings.forEach(AbstractBuilding::destroy);
}
Aggregations