use of com.lowdragmc.multiblocked.api.tile.ControllerTileEntity in project Multiblocked by Low-Drag-MC.
the class PatternWidget method onFormedSwitch.
private void onFormedSwitch(ClickData clickData, Boolean isPressed) {
MBPattern pattern = patterns[index];
ControllerTileEntity controllerBase = pattern.controllerBase;
if (isPressed) {
loadControllerFormed(pattern.blockMap.keySet(), controllerBase);
} else {
sceneWidget.setRenderedCore(pattern.blockMap.keySet(), null);
controllerBase.state = null;
controllerBase.onStructureInvalid();
}
}
use of com.lowdragmc.multiblocked.api.tile.ControllerTileEntity in project Multiblocked by Low-Drag-MC.
the class BlockPattern method checkPatternAt.
public boolean checkPatternAt(MultiblockState worldState, boolean savePredicate) {
ControllerTileEntity controller = worldState.getController();
if (controller == null) {
worldState.setError(new PatternStringError("no controller found"));
return false;
}
BlockPos centerPos = controller.getBlockPos();
Direction frontFacing = controller.getFrontFacing();
Set<MultiblockCapability<?>> inputCapabilities = controller.getDefinition().recipeMap.inputCapabilities;
Set<MultiblockCapability<?>> outputCapabilities = controller.getDefinition().recipeMap.outputCapabilities;
Direction[] facings = controller.getDefinition().allowRotate ? new Direction[] { frontFacing } : new Direction[] { Direction.SOUTH, Direction.NORTH, Direction.EAST, Direction.WEST };
for (Direction facing : facings) {
if (checkPatternAt(worldState, centerPos, facing, savePredicate, inputCapabilities, outputCapabilities)) {
return true;
}
}
return false;
}
use of com.lowdragmc.multiblocked.api.tile.ControllerTileEntity in project Multiblocked by Low-Drag-MC.
the class MultiblockState method onBlockStateChanged.
public void onBlockStateChanged(BlockPos pos) {
if (pos.equals(controllerPos)) {
if (this.getMatchContext().containsKey("renderMask")) {
MultiblockedNetworking.sendToAll(new SPacketRemoveDisabledRendering(controllerPos));
}
if (lastController != null) {
lastController.onStructureInvalid();
}
MultiblockWorldSavedData mbds = MultiblockWorldSavedData.getOrCreate(world);
mbds.removeMapping(this);
mbds.removeLoading(controllerPos);
} else if (error != UNLOAD_ERROR) {
ControllerTileEntity controller = getController();
if (controller != null && !controller.checkPattern()) {
controller.onStructureInvalid();
MultiblockWorldSavedData.getOrCreate(world).removeMapping(this);
}
}
}
use of com.lowdragmc.multiblocked.api.tile.ControllerTileEntity in project Multiblocked by Low-Drag-MC.
the class ItemMultiblockBuilder method onItemUseFirst.
@Override
public ActionResultType onItemUseFirst(ItemStack stack, ItemUseContext context) {
PlayerEntity player = context.getPlayer();
if (player != null) {
if (!player.level.isClientSide) {
TileEntity tileEntity = player.level.getBlockEntity(context.getClickedPos());
ItemStack hold = player.getItemInHand(context.getHand());
if (isItemMultiblockBuilder(hold) && tileEntity instanceof ControllerTileEntity) {
if (isRaw(hold)) {
BlockPattern pattern = ((ControllerTileEntity) tileEntity).getPattern();
if (pattern != null) {
pattern.autoBuild(player, new MultiblockState(player.level, context.getClickedPos()));
}
return ActionResultType.SUCCESS;
} else {
String json = hold.getOrCreateTagElement("pattern").getString("json");
String controller = hold.getOrCreateTagElement("pattern").getString("controller");
if (!json.isEmpty() && !controller.isEmpty()) {
if (controller.equals(((ControllerTileEntity) tileEntity).getDefinition().location.toString())) {
JsonBlockPattern jsonBlockPattern = Multiblocked.GSON.fromJson(json, JsonBlockPattern.class);
jsonBlockPattern.build().autoBuild(player, new MultiblockState(player.level, context.getClickedPos()));
return ActionResultType.SUCCESS;
}
}
}
}
}
}
return ActionResultType.PASS;
}
use of com.lowdragmc.multiblocked.api.tile.ControllerTileEntity in project Multiblocked by Low-Drag-MC.
the class MultiblockPreviewRenderer method renderWorldLastEvent.
@SubscribeEvent
public static void renderWorldLastEvent(RenderWorldLastEvent event) {
if (mbpPos != null) {
Minecraft mc = Minecraft.getInstance();
long time = System.currentTimeMillis();
if (time > mbpEndTime || !(mc.level != null && mc.level.getBlockEntity(mbpPos) instanceof ControllerTileEntity)) {
resetMultiblockRender();
layer = 0;
return;
}
MatrixStack stack = event.getMatrixStack();
Vector3d pos = mc.gameRenderer.getMainCamera().getPosition();
stack.pushPose();
stack.translate(-pos.x, -pos.y, -pos.z);
RenderSystem.enableTexture();
RenderSystem.enableBlend();
RenderSystem.enableCull();
RenderSystem.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
Minecraft.getInstance().getTextureManager().bind(AtlasTexture.LOCATION_BLOCKS);
RenderSystem.color4f(1F, 1F, 1F, 1F);
IRenderTypeBuffer.Impl buffer = IRenderTypeBuffer.immediate(Tessellator.getInstance().getBuilder());
render(stack, buffer);
buffer.endBatch();
stack.popPose();
}
}
Aggregations