use of com.ldtteam.structurize.blocks.interfaces.IBlueprintDataProvider in project Structurize by ldtteam.
the class ClientEventSubscriber method renderWorldLastEvent.
/**
* Used to catch the renderWorldLastEvent in order to draw the debug nodes for pathfinding.
*
* @param event the catched event.
*/
@SubscribeEvent
public static void renderWorldLastEvent(@NotNull final RenderWorldLastEvent event) {
Settings.instance.startStructurizePass();
OptifineCompat.getInstance().preBlueprintDraw();
final MatrixStack matrixStack = event.getMatrixStack();
final float partialTicks = event.getPartialTicks();
final IRenderTypeBuffer.Impl renderBuffer = renderBuffers.bufferSource();
final Supplier<IVertexBuilder> linesWithCullAndDepth = () -> renderBuffer.getBuffer(RenderType.lines());
final Supplier<IVertexBuilder> linesWithoutCullAndDepth = () -> renderBuffer.getBuffer(RenderUtils.LINES_GLINT);
final PlayerEntity player = Minecraft.getInstance().player;
final Blueprint blueprint = Settings.instance.getActiveStructure();
if (blueprint != null) {
Minecraft.getInstance().getProfiler().push("struct_render");
final BlockPos pos = Settings.instance.getPosition();
final BlockPos posMinusOffset = pos.subtract(blueprint.getPrimaryBlockOffset());
StructureClientHandler.renderStructure(blueprint, partialTicks, pos, matrixStack);
renderAnchorPos(pos, matrixStack, linesWithoutCullAndDepth.get());
RenderUtils.renderWhiteOutlineBox(posMinusOffset, posMinusOffset.offset(blueprint.getSizeX() - 1, blueprint.getSizeY() - 1, blueprint.getSizeZ() - 1), matrixStack, linesWithCullAndDepth.get());
renderBuffer.endBatch(RenderType.lines());
renderBuffer.endBatch(RenderUtils.LINES_GLINT);
Minecraft.getInstance().getProfiler().pop();
}
if (Settings.instance.getBox() != null) {
Minecraft.getInstance().getProfiler().push("struct_box");
// Used to render a red box around a scan's Primary offset (primary block)
Settings.instance.getAnchorPos().ifPresent(pos -> renderAnchorPos(pos, matrixStack, linesWithoutCullAndDepth.get()));
RenderUtils.renderWhiteOutlineBox(Settings.instance.getBox().getA(), Settings.instance.getBox().getB(), matrixStack, linesWithoutCullAndDepth.get());
renderBuffer.endBatch(RenderUtils.LINES_GLINT);
Minecraft.getInstance().getProfiler().pop();
}
final ItemStack itemStack = player.getItemInHand(Hand.MAIN_HAND);
if (itemStack.getItem() == ModItems.tagTool.get() && itemStack.getOrCreateTag().contains(ItemTagTool.TAG_ANCHOR_POS)) {
final BlockPos tagAnchor = BlockPosUtil.readFromNBT(itemStack.getTag(), ItemTagTool.TAG_ANCHOR_POS);
final TileEntity te = Minecraft.getInstance().player.level.getBlockEntity(tagAnchor);
renderAnchorPos(tagAnchor, matrixStack, linesWithoutCullAndDepth.get());
if (te instanceof IBlueprintDataProvider) {
final Map<BlockPos, List<String>> tagPosList = ((IBlueprintDataProvider) te).getWorldTagPosMap();
for (final Map.Entry<BlockPos, List<String>> entry : tagPosList.entrySet()) {
RenderUtils.renderWhiteOutlineBox(entry.getKey(), entry.getKey(), matrixStack, linesWithoutCullAndDepth.get());
IRenderTypeBuffer.Impl buffer = IRenderTypeBuffer.immediate(Tessellator.getInstance().getBuilder());
RenderUtils.renderDebugText(entry.getKey(), entry.getValue(), matrixStack, true, 3, buffer);
RenderSystem.disableDepthTest();
buffer.endBatch();
RenderSystem.enableDepthTest();
}
renderBuffer.endBatch(RenderUtils.LINES_GLINT);
}
}
renderBuffer.endBatch();
OptifineCompat.getInstance().postBlueprintDraw();
Settings.instance.endStructurizePass();
final Vector3d viewPosition = Minecraft.getInstance().gameRenderer.getMainCamera().getPosition();
matrixStack.pushPose();
matrixStack.translate(-viewPosition.x(), -viewPosition.y(), -viewPosition.z());
HookRegistries.render(matrixStack, partialTicks);
matrixStack.popPose();
}
use of com.ldtteam.structurize.blocks.interfaces.IBlueprintDataProvider in project Structurize by ldtteam.
the class ItemScanTool method canAttackBlock.
@Override
public boolean canAttackBlock(final BlockState state, final World worldIn, final BlockPos pos, final PlayerEntity player) {
if (!player.isShiftKeyDown()) {
return super.canAttackBlock(state, worldIn, pos, player);
}
if (worldIn.isClientSide()) {
LanguageHandler.sendMessageToPlayer(player, ANCHOR_POS_TKEY, pos.getX(), pos.getY(), pos.getZ());
}
ItemStack itemstack = player.getMainHandItem();
if (!itemstack.getItem().equals(getRegisteredItemInstance())) {
itemstack = player.getOffhandItem();
}
final TileEntity te = worldIn.getBlockEntity(pos);
if (te instanceof IBlueprintDataProvider && !((IBlueprintDataProvider) te).getSchematicName().isEmpty()) {
if (worldIn.isClientSide) {
Settings.instance.setAnchorPos(Optional.of(pos));
}
final BlockPos start = ((IBlueprintDataProvider) te).getInWorldCorners().getA();
final BlockPos end = ((IBlueprintDataProvider) te).getInWorldCorners().getB();
if (!(start.equals(pos)) && !(end.equals(pos))) {
if (worldIn.isClientSide) {
Settings.instance.setBox(((IBlueprintDataProvider) te).getInWorldCorners());
}
itemstack.getOrCreateTag().put(NBT_START_POS, NBTUtil.writeBlockPos(start));
itemstack.getOrCreateTag().put(NBT_END_POS, NBTUtil.writeBlockPos(end));
if (player instanceof ServerPlayerEntity) {
((ServerPlayerEntity) player).refreshContainer(player.inventoryMenu, player.inventory.items);
}
}
}
itemstack.getOrCreateTag().put(NBT_ANCHOR_POS, NBTUtil.writeBlockPos(pos));
return false;
}
use of com.ldtteam.structurize.blocks.interfaces.IBlueprintDataProvider in project Structurize by ldtteam.
the class ItemTagTool method canAttackBlock.
@Override
public boolean canAttackBlock(final BlockState state, final World worldIn, final BlockPos pos, final PlayerEntity player) {
final ItemStack stack = player.getMainHandItem();
if (stack.getItem() != ModItems.tagTool.get() || player == null || worldIn == null) {
return false;
}
BlockPos anchorPos = getAnchorPos(stack);
String currentTag = getCurrentTag(stack);
if (anchorPos == null) {
LanguageHandler.sendPlayerMessage(player, "com.ldtteam.structurize.gui.tagtool.noanchor");
return false;
}
if (currentTag.isEmpty()) {
LanguageHandler.sendPlayerMessage(player, "com.ldtteam.structurize.gui.tagtool.notag");
return false;
}
// Apply tag to item
BlockPos relativePos = pos.subtract(anchorPos);
final TileEntity te = worldIn.getBlockEntity(anchorPos);
if (!(te instanceof IBlueprintDataProvider)) {
LanguageHandler.sendPlayerMessage(player, "com.ldtteam.structurize.gui.tagtool.anchor.notvalid");
stack.getOrCreateTag().remove(TAG_ANCHOR_POS);
return false;
}
// add/remove tags
Map<BlockPos, List<String>> tagPosMap = ((IBlueprintDataProvider) te).getPositionedTags();
if (!tagPosMap.containsKey(relativePos) || !tagPosMap.get(relativePos).contains(currentTag)) {
((IBlueprintDataProvider) te).addTag(relativePos, currentTag);
if (worldIn.isClientSide()) {
LanguageHandler.sendPlayerMessage(player, "com.ldtteam.structurize.gui.tagtool.addtag", currentTag, new TranslationTextComponent(worldIn.getBlockState(pos).getBlock().getDescriptionId()));
}
} else {
((IBlueprintDataProvider) te).removeTag(relativePos, currentTag);
if (worldIn.isClientSide()) {
LanguageHandler.sendPlayerMessage(player, "com.ldtteam.structurize.gui.tagtool.removed", currentTag, new TranslationTextComponent(worldIn.getBlockState(pos).getBlock().getDescriptionId()));
}
}
return false;
}
use of com.ldtteam.structurize.blocks.interfaces.IBlueprintDataProvider in project minecolonies by ldtteam.
the class AbstractSchematicProvider method upgradeBuildingLevelToSchematicData.
@Override
public void upgradeBuildingLevelToSchematicData() {
final TileEntity tileEntity = colony.getWorld().getBlockEntity(getID());
if (tileEntity instanceof IBlueprintDataProvider) {
final IBlueprintDataProvider blueprintDataProvider = (IBlueprintDataProvider) tileEntity;
if (blueprintDataProvider.getSchematicName().isEmpty()) {
return;
}
setCorners(blueprintDataProvider.getInWorldCorners().getA(), blueprintDataProvider.getInWorldCorners().getB());
int level = 0;
try {
level = Integer.parseInt(blueprintDataProvider.getSchematicName().substring(blueprintDataProvider.getSchematicName().length() - 1));
} catch (NumberFormatException e) {
}
if (level > 0 && level >= getBuildingLevel() && level <= getMaxBuildingLevel()) {
if (level > getBuildingLevel()) {
FireworkUtils.spawnFireworksAtAABBCorners(getCorners(), colony.getWorld(), level);
}
setBuildingLevel(level);
onUpgradeComplete(level);
}
}
}
use of com.ldtteam.structurize.blocks.interfaces.IBlueprintDataProvider in project minecolonies by ldtteam.
the class CreativeBuildingStructureHandler method triggerSuccess.
@Override
public void triggerSuccess(final BlockPos pos, final List<ItemStack> list, final boolean placement) {
super.triggerSuccess(pos, list, placement);
final BlockPos worldPos = getProgressPosInWorld(pos);
final CompoundNBT teData = getBluePrint().getTileEntityData(worldPos, pos);
if (teData != null && teData.contains(TAG_BLUEPRINTDATA)) {
final TileEntity te = getWorld().getBlockEntity(worldPos);
if (te != null) {
((IBlueprintDataProvider) te).readSchematicDataFromNBT(teData);
((ServerWorld) getWorld()).getChunkSource().blockChanged(worldPos);
te.setChanged();
}
}
if (building != null) {
building.registerBlockPosition(getBluePrint().getBlockState(pos), worldPos, this.getWorld());
}
}
Aggregations