use of com.minecolonies.coremod.tileentities.TileEntityDecorationController in project minecolonies by ldtteam.
the class DecorationBuildRequestMessage method onExecute.
@Override
public void onExecute(final NetworkEvent.Context ctxIn, final boolean isLogicalServer) {
final IColony colony = IColonyManager.getInstance().getColonyByPosFromDim(dimension, pos);
if (colony == null) {
return;
}
final PlayerEntity player = ctxIn.getSender();
// Verify player has permission to change this huts settings
if (!colony.getPermissions().hasPermission(player, Action.MANAGE_HUTS)) {
return;
}
final TileEntity entity = player.getCommandSenderWorld().getBlockEntity(pos);
if (entity instanceof TileEntityDecorationController) {
final Optional<Map.Entry<Integer, IWorkOrder>> wo = colony.getWorkManager().getWorkOrders().entrySet().stream().filter(entry -> entry.getValue() instanceof WorkOrderBuildDecoration).filter(entry -> ((WorkOrderBuildDecoration) entry.getValue()).getSchematicLocation().equals(pos)).findFirst();
if (wo.isPresent()) {
colony.getWorkManager().removeWorkOrder(wo.get().getKey());
return;
}
int difference = 0;
final LoadOnlyStructureHandler structure = new LoadOnlyStructureHandler(colony.getWorld(), this.pos, name + level, new PlacementSettings(), true);
final Blueprint blueprint = structure.getBluePrint();
if (blueprint != null) {
final BlockState structureState = structure.getBluePrint().getBlockInfoAsMap().get(structure.getBluePrint().getPrimaryBlockOffset()).getState();
if (structureState != null) {
if (!(structureState.getBlock() instanceof BlockDecorationController)) {
Log.getLogger().error(String.format("Schematic %s doesn't have a correct Primary Offset", name + level));
return;
}
final int structureRotation = structureState.getValue(BlockDecorationController.FACING).get2DDataValue();
final int worldRotation = colony.getWorld().getBlockState(this.pos).getValue(BlockDecorationController.FACING).get2DDataValue();
if (structureRotation <= worldRotation) {
difference = worldRotation - structureRotation;
} else {
difference = 4 + worldRotation - structureRotation;
}
}
}
final BlockState state = player.getCommandSenderWorld().getBlockState(pos);
final WorkOrderBuildDecoration order = new WorkOrderBuildDecoration(name + level, name + level, difference, pos, state.getValue(BlockDecorationController.MIRROR));
if (level != ((TileEntityDecorationController) entity).getTier()) {
order.setLevelUp();
}
colony.getWorkManager().addWorkOrder(order, false);
}
}
use of com.minecolonies.coremod.tileentities.TileEntityDecorationController in project minecolonies by ldtteam.
the class DecorationControllerUpdateMessage method onExecute.
@Override
public void onExecute(final NetworkEvent.Context ctxIn, final boolean isLogicalServer) {
final PlayerEntity player = ctxIn.getSender();
final TileEntity tileEntity = player.getCommandSenderWorld().getBlockEntity(pos);
if (tileEntity instanceof TileEntityDecorationController) {
final BlockState state = player.getCommandSenderWorld().getBlockState(pos);
final Direction basicFacing = state.getValue(BlockDecorationController.FACING);
((TileEntityDecorationController) tileEntity).setSchematicPath(name + level);
((TileEntityDecorationController) tileEntity).setTier(level);
((TileEntityDecorationController) tileEntity).setBasicFacing(basicFacing);
}
}
use of com.minecolonies.coremod.tileentities.TileEntityDecorationController in project minecolonies by ldtteam.
the class AbstractEntityAIStructure method loadStructure.
/**
* Loads the structure given the name, rotation and position.
*
* @param name the name to retrieve it.
* @param rotateTimes number of times to rotateWithMirror it.
* @param position the position to set it.
* @param isMirrored is the structure mirroed?
* @param removal if removal step.
*/
public void loadStructure(@NotNull final String name, final int rotateTimes, final BlockPos position, final boolean isMirrored, final boolean removal) {
final BuildingStructureHandler<J, B> structure;
IBuilding colonyBuilding = worker.getCitizenColonyHandler().getColony().getBuildingManager().getBuilding(position);
final TileEntity entity = world.getBlockEntity(position);
if (removal) {
structure = new BuildingStructureHandler<>(world, position, name, new PlacementSettings(isMirrored ? Mirror.FRONT_BACK : Mirror.NONE, BlockPosUtil.getRotationFromRotations(rotateTimes)), this, new BuildingStructureHandler.Stage[] { REMOVE_WATER, REMOVE });
getOwnBuilding().setTotalStages(2);
} else if ((colonyBuilding != null && (colonyBuilding.getBuildingLevel() > 0 || colonyBuilding.hasParent())) || (entity instanceof TileEntityDecorationController && ((TileEntityDecorationController) entity).getTier() > 0)) {
structure = new BuildingStructureHandler<>(world, position, name, new PlacementSettings(isMirrored ? Mirror.FRONT_BACK : Mirror.NONE, BlockPosUtil.getRotationFromRotations(rotateTimes)), this, new BuildingStructureHandler.Stage[] { BUILD_SOLID, CLEAR_WATER, CLEAR_NON_SOLIDS, DECORATE, SPAWN });
getOwnBuilding().setTotalStages(5);
} else {
structure = new BuildingStructureHandler<>(world, position, name, new PlacementSettings(isMirrored ? Mirror.FRONT_BACK : Mirror.NONE, BlockPosUtil.getRotationFromRotations(rotateTimes)), this, new BuildingStructureHandler.Stage[] { CLEAR, BUILD_SOLID, CLEAR_WATER, CLEAR_NON_SOLIDS, DECORATE, SPAWN });
getOwnBuilding().setTotalStages(6);
}
if (!structure.hasBluePrint()) {
handleSpecificCancelActions();
Log.getLogger().warn("Couldn't find structure with name: " + name + " aborting loading procedure");
return;
}
job.setBlueprint(structure.getBluePrint());
job.getBlueprint().rotateWithMirror(BlockPosUtil.getRotationFromRotations(rotateTimes), isMirrored ? Mirror.FRONT_BACK : Mirror.NONE, world);
setStructurePlacer(structure);
if (getProgressPos() != null) {
structure.setStage(getProgressPos().getB());
}
}
use of com.minecolonies.coremod.tileentities.TileEntityDecorationController in project minecolonies by Minecolonies.
the class DecorationControllerUpdateMessage method onExecute.
@Override
public void onExecute(final NetworkEvent.Context ctxIn, final boolean isLogicalServer) {
final PlayerEntity player = ctxIn.getSender();
final TileEntity tileEntity = player.getCommandSenderWorld().getBlockEntity(pos);
if (tileEntity instanceof TileEntityDecorationController) {
final BlockState state = player.getCommandSenderWorld().getBlockState(pos);
final Direction basicFacing = state.getValue(BlockDecorationController.FACING);
((TileEntityDecorationController) tileEntity).setSchematicPath(name + level);
((TileEntityDecorationController) tileEntity).setTier(level);
((TileEntityDecorationController) tileEntity).setBasicFacing(basicFacing);
}
}
use of com.minecolonies.coremod.tileentities.TileEntityDecorationController in project minecolonies by Minecolonies.
the class DecorationBuildRequestMessage method onExecute.
@Override
public void onExecute(final NetworkEvent.Context ctxIn, final boolean isLogicalServer) {
final IColony colony = IColonyManager.getInstance().getColonyByPosFromDim(dimension, pos);
if (colony == null) {
return;
}
final PlayerEntity player = ctxIn.getSender();
// Verify player has permission to change this huts settings
if (!colony.getPermissions().hasPermission(player, Action.MANAGE_HUTS)) {
return;
}
final TileEntity entity = player.getCommandSenderWorld().getBlockEntity(pos);
if (entity instanceof TileEntityDecorationController) {
final Optional<Map.Entry<Integer, IWorkOrder>> wo = colony.getWorkManager().getWorkOrders().entrySet().stream().filter(entry -> entry.getValue() instanceof WorkOrderBuildDecoration).filter(entry -> ((WorkOrderBuildDecoration) entry.getValue()).getSchematicLocation().equals(pos)).findFirst();
if (wo.isPresent()) {
colony.getWorkManager().removeWorkOrder(wo.get().getKey());
return;
}
int difference = 0;
final LoadOnlyStructureHandler structure = new LoadOnlyStructureHandler(colony.getWorld(), this.pos, name + level, new PlacementSettings(), true);
final Blueprint blueprint = structure.getBluePrint();
if (blueprint != null) {
final BlockState structureState = structure.getBluePrint().getBlockInfoAsMap().get(structure.getBluePrint().getPrimaryBlockOffset()).getState();
if (structureState != null) {
if (!(structureState.getBlock() instanceof BlockDecorationController)) {
Log.getLogger().error(String.format("Schematic %s doesn't have a correct Primary Offset", name + level));
return;
}
final int structureRotation = structureState.getValue(BlockDecorationController.FACING).get2DDataValue();
final int worldRotation = colony.getWorld().getBlockState(this.pos).getValue(BlockDecorationController.FACING).get2DDataValue();
if (structureRotation <= worldRotation) {
difference = worldRotation - structureRotation;
} else {
difference = 4 + worldRotation - structureRotation;
}
}
}
final BlockState state = player.getCommandSenderWorld().getBlockState(pos);
final WorkOrderBuildDecoration order = new WorkOrderBuildDecoration(name + level, name + level, difference, pos, state.getValue(BlockDecorationController.MIRROR));
if (level != ((TileEntityDecorationController) entity).getTier()) {
order.setLevelUp();
}
colony.getWorkManager().addWorkOrder(order, false);
}
}
Aggregations