use of com.ldtteam.structures.blueprints.v1.Blueprint in project minecolonies by Minecolonies.
the class ClientEventHandler method renderWorldLastEvent.
/**
* Used to catch the renderWorldLastEvent in order to draw the debug nodes for pathfinding.
*
* @param event the catched event.
*/
@SubscribeEvent(priority = EventPriority.LOWEST)
public static void renderWorldLastEvent(@NotNull final RenderWorldLastEvent event) {
Pathfinding.debugDraw(event.getPartialTicks(), event.getMatrixStack());
final Blueprint structure = Settings.instance.getActiveStructure();
final ClientWorld world = Minecraft.getInstance().level;
final PlayerEntity player = Minecraft.getInstance().player;
if (structure != null) {
handleRenderStructure(event, world, player);
}
if (player.getMainHandItem().getItem() == ModItems.scepterGuard) {
handleRenderScepterGuard(event, world, player);
} else if (player.getMainHandItem().getItem() == ModItems.bannerRallyGuards) {
handleRenderBannerRallyGuards(event, world, player);
} else if (player.getMainHandItem().getItem() == com.ldtteam.structurize.items.ModItems.buildTool.get()) {
handleRenderBuildTool(event, world, player);
} else {
alreadyRequestedStructures.clear();
}
DebugRendererChunkBorder.renderWorldLastEvent(event);
renderBuffer.endBatch();
}
use of com.ldtteam.structures.blueprints.v1.Blueprint 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);
}
}
use of com.ldtteam.structures.blueprints.v1.Blueprint in project minecolonies by Minecolonies.
the class ItemSupplyChestDeployer method canShipBePlaced.
/**
* Checks if the ship can be placed.
*
* @param world the world.
* @param pos the pos.
* @param ship the blueprint.
* @param placementErrorList the list of placement errors.
* @param placer the placer.
* @return true if so.
*/
public static boolean canShipBePlaced(@NotNull final World world, @NotNull final BlockPos pos, final Blueprint ship, @NotNull final List<PlacementError> placementErrorList, final PlayerEntity placer) {
if (MineColonies.getConfig().getServer().noSupplyPlacementRestrictions.get()) {
return true;
}
final int sizeX = ship.getSizeX();
final int sizeZ = ship.getSizeZ();
final int waterLevel = BlueprintTagUtils.getNumberOfGroundLevels(ship, DEFAULT_WATER_LEVELS);
final BlockPos zeroPos = pos.subtract(ship.getPrimaryBlockOffset());
for (int z = zeroPos.getZ(); z < zeroPos.getZ() + sizeZ; z++) {
for (int x = zeroPos.getX(); x < zeroPos.getX() + sizeX; x++) {
for (int y = zeroPos.getY(); y <= zeroPos.getY() + waterLevel + SCAN_HEIGHT; y++) {
if (y < zeroPos.getY() + waterLevel) {
checkFluidAndNotInColony(world, new BlockPos(x, y, z), placementErrorList, placer);
} else if (world.getBlockState(new BlockPos(x, y, z)).getMaterial().isSolid()) {
final PlacementError placementError = new PlacementError(PlacementError.PlacementErrorType.NEEDS_AIR_ABOVE, new BlockPos(x, y, z));
placementErrorList.add(placementError);
}
}
}
}
return placementErrorList.isEmpty();
}
use of com.ldtteam.structures.blueprints.v1.Blueprint in project Structurize by ldtteam.
the class BlueprintHandler method draw.
/**
* Draw a blueprint with a rotation, mirror and offset.
*
* @param blueprint the wayPointBlueprint to draw.
* @param pos its position.
*/
public void draw(final Blueprint blueprint, final BlockPos pos, final MatrixStack stack, final float partialTicks) {
if (blueprint == null) {
Log.getLogger().warn("Trying to draw null blueprint!");
return;
}
Minecraft.getInstance().getProfiler().push("struct_render_cache");
final int blueprintHash = blueprint.hashCode();
final BlueprintRenderer rendererRef = rendererCache.get(blueprintHash);
final BlueprintRenderer renderer = rendererRef == null ? BlueprintRenderer.buildRendererForBlueprint(blueprint) : rendererRef;
if (rendererRef == null) {
rendererCache.put(blueprintHash, renderer);
}
renderer.updateBlueprint(blueprint);
renderer.draw(pos, stack, partialTicks);
evictTimeCache.put(blueprintHash, System.currentTimeMillis());
Minecraft.getInstance().getProfiler().pop();
}
use of com.ldtteam.structures.blueprints.v1.Blueprint in project Structurize by ldtteam.
the class WindowShapeTool method init.
private void init(final BlockPos pos, final boolean shouldUpdate) {
if (!hasPermission())
return;
@Nullable final Blueprint structure = Settings.instance.getActiveStructure();
if (structure != null) {
rotation = Settings.instance.getRotation();
this.shapeWidth = Settings.instance.getWidth();
this.shapeLength = Settings.instance.getLength();
this.shapeHeight = Settings.instance.getHeight();
this.shapeFrequency = Settings.instance.getFrequency();
this.shapeEquation = Settings.instance.getEquation();
} else if (pos != null) {
this.pos = pos;
Settings.instance.setPosition(pos);
Settings.instance.setRotation(0);
}
// Register all necessary buttons with the window.
registerButton(BUTTON_CONFIRM, this::confirmClicked);
registerButton(BUTTON_CANCEL, this::cancelClicked);
registerButton(BUTTON_LEFT, this::moveLeftClicked);
registerButton(BUTTON_MIRROR, this::mirror);
registerButton(BUTTON_RIGHT, this::moveRightClicked);
registerButton(BUTTON_BACKWARD, this::moveBackClicked);
registerButton(BUTTON_FORWARD, this::moveForwardClicked);
registerButton(BUTTON_UP, WindowShapeTool::moveUpClicked);
registerButton(BUTTON_DOWN, WindowShapeTool::moveDownClicked);
registerButton(BUTTON_ROTATE_RIGHT, this::rotateRightClicked);
registerButton(BUTTON_ROTATE_LEFT, this::rotateLeftClicked);
registerButton(BUTTON_PICK_MAIN_BLOCK, this::pickMainBlock);
registerButton(BUTTON_PICK_FILL_BLOCK, this::pickFillBlock);
registerButton(BUTTON_UNDOREDO, b -> {
close();
new WindowUndoRedo().open();
});
registerButton(BUTTON_HOLLOW, this::hollowShapeToggle);
registerButton(BUTTON_PASTE, this::pasteClicked);
inputWidth = findPaneOfTypeByID(INPUT_WIDTH, TextField.class);
inputLength = findPaneOfTypeByID(INPUT_LENGTH, TextField.class);
inputHeight = findPaneOfTypeByID(INPUT_HEIGHT, TextField.class);
inputFrequency = findPaneOfTypeByID(INPUT_FREQUENCY, TextField.class);
inputShape = findPaneOfTypeByID(INPUT_SHAPE, TextField.class);
inputWidth.setText(Integer.toString(Settings.instance.getWidth()));
inputLength.setText(Integer.toString(Settings.instance.getLength()));
inputHeight.setText(Integer.toString(Settings.instance.getHeight()));
inputFrequency.setText(Integer.toString(Settings.instance.getFrequency()));
inputShape.setText(Settings.instance.getEquation());
registerButton(INPUT_WIDTH + BUTTON_MINUS, () -> adjust(inputWidth, Settings.instance.getWidth() - 1));
registerButton(INPUT_WIDTH + BUTTON_PLUS, () -> adjust(inputWidth, Settings.instance.getWidth() + 1));
registerButton(INPUT_LENGTH + BUTTON_MINUS, () -> adjust(inputLength, Settings.instance.getLength() - 1));
registerButton(INPUT_LENGTH + BUTTON_PLUS, () -> adjust(inputLength, Settings.instance.getLength() + 1));
registerButton(INPUT_HEIGHT + BUTTON_MINUS, () -> adjust(inputHeight, Settings.instance.getHeight() - 1));
registerButton(INPUT_HEIGHT + BUTTON_PLUS, () -> adjust(inputHeight, Settings.instance.getHeight() + 1));
registerButton(INPUT_FREQUENCY + BUTTON_MINUS, () -> adjust(inputFrequency, Settings.instance.getFrequency() - 1));
registerButton(INPUT_FREQUENCY + BUTTON_PLUS, () -> adjust(inputFrequency, Settings.instance.getFrequency() + 1));
sections.clear();
sections.addAll(Arrays.stream(Shape.values()).map(Enum::name).collect(Collectors.toList()));
sectionsDropDownList = findPaneOfTypeByID(DROPDOWN_STYLE_ID, DropDownList.class);
sectionsDropDownList.setHandler(this::onDropDownListChanged);
sectionsDropDownList.setDataProvider(new SectionDropDownList());
sectionsDropDownList.setSelectedIndex(Settings.instance.getShape().ordinal());
registerButton("nextShape", sectionsDropDownList::selectNext);
registerButton("previousShape", sectionsDropDownList::selectPrevious);
disableInputIfNecessary();
if (structure == null || shouldUpdate) {
genShape();
}
updateRotationState();
findPaneOfTypeByID(BUTTON_HOLLOW, ToggleButton.class).setActiveState(Settings.instance.isHollow() ? "hollow" : "solid");
}
Aggregations