use of gregtech.api.metatileentity.multiblock.MultiblockControllerBase in project GregTech by GregTechCEu.
the class MetaTileEntityMonitorScreen method createUI.
@Override
protected ModularUI createUI(EntityPlayer entityPlayer) {
MultiblockControllerBase controller = this.getController();
if (controller instanceof MetaTileEntityCentralMonitor && ((MetaTileEntityCentralMonitor) controller).isActive()) {
int width = 330;
int height = 260;
ToggleButtonWidget[] buttons = new ToggleButtonWidget[5];
buttons[0] = new ToggleButtonWidget(width - 135, 25, 20, 20, GuiTextures.BUTTON_FLUID, () -> this.mode == CoverDigitalInterface.MODE.FLUID, (isPressed) -> {
if (isPressed)
setMode(CoverDigitalInterface.MODE.FLUID);
}).setTooltipText("metaitem.cover.digital.mode.fluid");
buttons[1] = new ToggleButtonWidget(width - 115, 25, 20, 20, GuiTextures.BUTTON_ITEM, () -> this.mode == CoverDigitalInterface.MODE.ITEM, (isPressed) -> {
if (isPressed)
setMode(CoverDigitalInterface.MODE.ITEM);
}).setTooltipText("metaitem.cover.digital.mode.item");
buttons[2] = new ToggleButtonWidget(width - 95, 25, 20, 20, GuiTextures.BUTTON_ENERGY, () -> this.mode == CoverDigitalInterface.MODE.ENERGY, (isPressed) -> {
if (isPressed)
setMode(CoverDigitalInterface.MODE.ENERGY);
}).setTooltipText("metaitem.cover.digital.mode.energy");
buttons[3] = new ToggleButtonWidget(width - 75, 25, 20, 20, GuiTextures.BUTTON_MACHINE, () -> this.mode == CoverDigitalInterface.MODE.MACHINE, (isPressed) -> {
if (isPressed)
setMode(CoverDigitalInterface.MODE.MACHINE);
}).setTooltipText("metaitem.cover.digital.mode.machine");
buttons[4] = new ToggleButtonWidget(width - 35, 25, 20, 20, GuiTextures.BUTTON_INTERFACE, () -> this.mode == CoverDigitalInterface.MODE.PROXY, (isPressed) -> {
if (isPressed)
setMode(CoverDigitalInterface.MODE.PROXY);
}).setTooltipText("metaitem.cover.digital.mode.proxy");
List<CoverDigitalInterface> covers = new ArrayList<>();
((MetaTileEntityCentralMonitor) controller).getAllCovers().forEach(coverPos -> covers.add(getCoverFromPosSide(coverPos)));
WidgetPluginConfig pluginWidget = new WidgetPluginConfig();
WidgetPluginConfig mainGroup = new WidgetPluginConfig().setSize(width, height);
mainGroup.widget(new LabelWidget(15, 55, "monitor.gui.title.scale", 0xFFFFFFFF)).widget(new ClickButtonWidget(50, 50, 20, 20, "-1", (data) -> setConfig(this.slot, ((float) Math.round((scale - (data.isShiftClick ? 1.0f : 0.1f)) * 10) / 10), this.frameColor))).widget(new ClickButtonWidget(130, 50, 20, 20, "+1", (data) -> setConfig(this.slot, ((float) Math.round((scale + (data.isShiftClick ? 1.0f : 0.1f)) * 10) / 10), this.frameColor))).widget(new ImageWidget(70, 50, 60, 20, GuiTextures.DISPLAY)).widget(new SimpleTextWidget(100, 60, "", 16777215, () -> Float.toString(scale))).widget(new LabelWidget(15, 85, "monitor.gui.title.argb", 0xFFFFFFFF)).widget(new WidgetARGB(50, 80, 20, this.frameColor, (color) -> setConfig(this.slot, this.scale, color))).widget(new LabelWidget(15, 110, "monitor.gui.title.slot", 0xFFFFFFFF)).widget(new ClickButtonWidget(50, 105, 20, 20, "-1", (data) -> setConfig(this.slot - 1, this.scale, this.frameColor))).widget(new ClickButtonWidget(130, 105, 20, 20, "+1", (data) -> setConfig(this.slot + 1, this.scale, this.frameColor))).widget(new ImageWidget(70, 105, 60, 20, GuiTextures.DISPLAY)).widget(new SimpleTextWidget(100, 115, "", 16777215, () -> Integer.toString(slot))).widget(new LabelWidget(15, 135, "monitor.gui.title.plugin", 0xFFFFFFFF)).widget(new SlotWidget(inventory, 0, 50, 130, true, true).setBackgroundTexture(GuiTextures.SLOT).setChangeListener(() -> {
if (this.getWorld() != null && !this.getWorld().isRemote) {
MonitorPluginBaseBehavior behavior = MonitorPluginBaseBehavior.getBehavior(inventory.getStackInSlot(0));
if (behavior == null) {
unloadPlugin();
} else {
loadPlugin(behavior);
}
writeCustomData(GregtechDataCodes.UPDATE_PLUGIN_ITEM, packetBuffer -> packetBuffer.writeItemStack(inventory.getStackInSlot(0)));
}
})).widget(new ClickButtonWidget(80, 130, 40, 20, "monitor.gui.title.config", (data) -> {
if (plugin != null && mainGroup.isVisible()) {
plugin.customUI(pluginWidget, this.getHolder(), entityPlayer);
mainGroup.setVisible(false);
}
}) {
@Override
protected void triggerButton() {
super.triggerButton();
if (plugin != null && mainGroup.isVisible()) {
plugin.customUI(pluginWidget, getHolder(), entityPlayer);
mainGroup.setVisible(false);
}
}
}).widget(new WidgetCoverList(width - 140, 50, 120, 11, covers, getCoverFromPosSide(this.coverPos), (coverPos) -> {
if (coverPos == null) {
this.setMode(null, this.mode);
} else {
this.setMode(new BlockPosFace(coverPos.coverHolder.getPos(), coverPos.attachedSide));
}
})).widget(buttons[0]).widget(buttons[1]).widget(buttons[2]).widget(buttons[3]).widget(buttons[4]).bindPlayerInventory(entityPlayer.inventory, GuiTextures.SLOT, 15, 170);
return ModularUI.builder(GuiTextures.BOXED_BACKGROUND, width, height).widget(pluginWidget).widget(mainGroup).widget(new WidgetMonitorScreen(330, 0, 150, this)).widget(new LabelWidget(15, 13, "gregtech.machine.monitor_screen.name", 0XFFFFFFFF)).widget(new ClickButtonWidget(15, 25, 40, 20, "monitor.gui.title.back", data -> {
if (mainGroup.isVisible() && ((MetaTileEntityCentralMonitor) controller).isActive() && controller.isValid()) {
MetaTileEntityUIFactory.INSTANCE.openUI(controller.getHolder(), (EntityPlayerMP) entityPlayer);
} else if (!mainGroup.isVisible()) {
pluginWidget.removePluginWidget();
mainGroup.setVisible(true);
if (plugin != null) {
plugin.markAsDirty();
}
}
}) {
@Override
protected void triggerButton() {
super.triggerButton();
if (!mainGroup.isVisible()) {
pluginWidget.removePluginWidget();
mainGroup.setVisible(true);
if (plugin != null) {
plugin.markAsDirty();
}
}
}
}).bindCloseListener(() -> {
if (plugin != null) {
plugin.markAsDirty();
}
}).build(this.getHolder(), entityPlayer);
}
return null;
}
use of gregtech.api.metatileentity.multiblock.MultiblockControllerBase in project GregTech by GregTechCEu.
the class MetaTileEntityMonitorScreen method onLeftClick.
@Override
public void onLeftClick(EntityPlayer playerIn, EnumFacing facing, CuboidRayTraceResult hitResult) {
if (playerIn.world.getTotalWorldTime() - lastClickTime < 2 && playerIn.getPersistentID().equals(lastClickUUID)) {
return;
}
lastClickTime = playerIn.world.getTotalWorldTime();
lastClickUUID = playerIn.getPersistentID();
MultiblockControllerBase controller = this.getController();
if (controller != null && controller.getFrontFacing() == facing) {
handleHitResultWithScale(playerIn, null, facing, false, hitResult);
}
}
use of gregtech.api.metatileentity.multiblock.MultiblockControllerBase in project GregTech by GregTechCEu.
the class MultiBlockPreviewARApp method tickAR.
@SideOnly(Side.CLIENT)
@Override
public void tickAR(EntityPlayer player) {
World world = player.world;
// 0 - 26
int tick = Math.abs(player.ticksExisted % 27);
if (tick == 0) {
boolean reRender = false;
Iterator<MultiblockControllerBase> iterator = controllerList.keySet().iterator();
if (iterator.hasNext()) {
MultiblockControllerBase controller = iterator.next();
if (!controller.isValid() || controller.isStructureFormed() || !inRange(player.getPosition(), controller.getPos())) {
iterator.remove();
reRender = true;
}
}
for (MultiblockControllerBase controllerBase : found) {
if (!controllerList.containsKey(controllerBase)) {
List<MultiblockShapeInfo> shapeInfos = controllerBase.getMatchingShapes();
if (!shapeInfos.isEmpty()) {
controllerList.put(controllerBase, shapeInfos.get(0));
reRender = true;
}
}
}
found.clear();
lastPos = player.getPosition();
if (reRender) {
// allocate op list
opList = GLAllocation.generateDisplayLists(1);
GlStateManager.glNewList(opList, GL11.GL_COMPILE);
controllerList.forEach((controller, shapes) -> MultiblockPreviewRenderer.renderControllerInList(controller, shapes, 0));
GlStateManager.glEndList();
}
}
if (lastPos == null) {
lastPos = player.getPosition();
}
for (int i = tick * 1000; i < (tick + 1) * 1000; i++) {
int x = i % 30 - 15;
int y = (i / 30) % 30 - 15;
int z = (i / 900) - 15;
TileEntity tileEntity = world.getTileEntity(lastPos.add(x, y, z));
if (tileEntity instanceof MetaTileEntityHolder) {
if (((MetaTileEntityHolder) tileEntity).getMetaTileEntity() instanceof MultiblockControllerBase) {
found.add((MultiblockControllerBase) ((MetaTileEntityHolder) tileEntity).getMetaTileEntity());
}
}
}
}
use of gregtech.api.metatileentity.multiblock.MultiblockControllerBase in project GregTech by GregTechCEu.
the class MultiBlockPreviewARApp method drawBuilderButton.
private void drawBuilderButton(double x, double y, int width, int height) {
if (Shaders.allowedShader()) {
float time = (gui.entityPlayer.ticksExisted + partialTicks) / 20f;
MultiblockControllerBase controllerBase = getController();
int color = controllerBase == null ? -1 : controllerBase.getPaintingColorForRendering();
if (controllerBase != null) {
GlStateManager.setActiveTexture(GL13.GL_TEXTURE0);
GlStateManager.enableTexture2D();
RenderUtil.bindTextureAtlasSprite(controllerBase.getFrontDefaultTexture());
GlStateManager.setActiveTexture(GL13.GL_TEXTURE1);
GlStateManager.enableTexture2D();
RenderUtil.bindTextureAtlasSprite(controllerBase.getBaseTexture(null).getParticleSprite());
}
ShaderTexture.createShader("showcube.frag").draw(x, y, width, height, uniformCache -> {
uniformCache.glUniform1I("faceTexture", 0);
uniformCache.glUniform1I("baseTexture", 1);
uniformCache.glUniform1F("u_time", time);
uniformCache.glUniform3F("f_color", (color >> 16 & 255) / 255.0F, (color >> 8 & 255) / 255.0F, (color & 255) / 255.0F);
uniformCache.glUniformBoolean("block", controllerBase != null);
if (isMouseOver((int) x, (int) y, width, height, lastMouseX, lastMouseY)) {
uniformCache.glUniform2F("u_mouse", (float) (((lastMouseX - x) / 2 + width / 3) * ConfigHolder.client.resolution), (float) (height / 2 * ConfigHolder.client.resolution));
}
});
GlStateManager.setActiveTexture(GL13.GL_TEXTURE1);
GlStateManager.bindTexture(0);
GlStateManager.setActiveTexture(GL13.GL_TEXTURE0);
GlStateManager.bindTexture(0);
} else {
GuiTextures.MULTIBLOCK_CATEGORY.draw(x, y, width, height);
}
}
use of gregtech.api.metatileentity.multiblock.MultiblockControllerBase in project GregTech by GregTechCEu.
the class BlockPattern method autoBuild.
public void autoBuild(EntityPlayer player, MultiblockControllerBase controllerBase) {
World world = player.world;
BlockWorldState worldState = new BlockWorldState();
int minZ = -centerOffset[4];
EnumFacing facing = controllerBase.getFrontFacing().getOpposite();
BlockPos centerPos = controllerBase.getPos();
Map<TraceabilityPredicate.SimplePredicate, BlockInfo[]> cacheInfos = new HashMap<>();
Map<TraceabilityPredicate.SimplePredicate, Integer> cacheGlobal = new HashMap<>();
Map<BlockPos, Object> blocks = new HashMap<>();
blocks.put(controllerBase.getPos(), controllerBase);
for (int c = 0, z = minZ++, r; c < this.fingerLength; c++) {
for (r = 0; r < aisleRepetitions[c][0]; r++) {
Map<TraceabilityPredicate.SimplePredicate, Integer> cacheLayer = new HashMap<>();
for (int b = 0, y = -centerOffset[1]; b < this.thumbLength; b++, y++) {
for (int a = 0, x = -centerOffset[0]; a < this.palmLength; a++, x++) {
TraceabilityPredicate predicate = this.blockMatches[c][b][a];
BlockPos pos = setActualRelativeOffset(x, y, z, facing).add(centerPos.getX(), centerPos.getY(), centerPos.getZ());
worldState.update(world, pos, matchContext, globalCount, layerCount, predicate);
if (!world.getBlockState(pos).getMaterial().isReplaceable()) {
blocks.put(pos, world.getBlockState(pos));
for (TraceabilityPredicate.SimplePredicate limit : predicate.limited) {
limit.testLimited(worldState);
}
} else {
boolean find = false;
BlockInfo[] infos = new BlockInfo[0];
for (TraceabilityPredicate.SimplePredicate limit : predicate.limited) {
if (limit.minLayerCount > 0) {
if (!cacheLayer.containsKey(limit)) {
cacheLayer.put(limit, 1);
} else if (cacheLayer.get(limit) < limit.minLayerCount && (limit.maxLayerCount == -1 || cacheLayer.get(limit) < limit.maxLayerCount)) {
cacheLayer.put(limit, cacheLayer.get(limit) + 1);
} else {
continue;
}
} else {
continue;
}
if (!cacheInfos.containsKey(limit)) {
cacheInfos.put(limit, limit.candidates == null ? null : limit.candidates.get());
}
infos = cacheInfos.get(limit);
find = true;
break;
}
if (!find) {
for (TraceabilityPredicate.SimplePredicate limit : predicate.limited) {
if (limit.minGlobalCount > 0) {
if (!cacheGlobal.containsKey(limit)) {
cacheGlobal.put(limit, 1);
} else if (cacheGlobal.get(limit) < limit.minGlobalCount && (limit.maxGlobalCount == -1 || cacheGlobal.get(limit) < limit.maxGlobalCount)) {
cacheGlobal.put(limit, cacheGlobal.get(limit) + 1);
} else {
continue;
}
} else {
continue;
}
if (!cacheInfos.containsKey(limit)) {
cacheInfos.put(limit, limit.candidates == null ? null : limit.candidates.get());
}
infos = cacheInfos.get(limit);
find = true;
break;
}
}
if (!find) {
// no limited
for (TraceabilityPredicate.SimplePredicate limit : predicate.limited) {
if (limit.maxLayerCount != -1 && cacheLayer.getOrDefault(limit, Integer.MAX_VALUE) == limit.maxLayerCount)
continue;
if (limit.maxGlobalCount != -1 && cacheGlobal.getOrDefault(limit, Integer.MAX_VALUE) == limit.maxGlobalCount)
continue;
if (!cacheInfos.containsKey(limit)) {
cacheInfos.put(limit, limit.candidates == null ? null : limit.candidates.get());
}
if (cacheLayer.containsKey(limit)) {
cacheLayer.put(limit, cacheLayer.get(limit) + 1);
} else {
cacheLayer.put(limit, 1);
}
if (cacheGlobal.containsKey(limit)) {
cacheGlobal.put(limit, cacheGlobal.get(limit) + 1);
} else {
cacheGlobal.put(limit, 1);
}
infos = ArrayUtils.addAll(infos, cacheInfos.get(limit));
}
for (TraceabilityPredicate.SimplePredicate common : predicate.common) {
if (!cacheInfos.containsKey(common)) {
cacheInfos.put(common, common.candidates == null ? null : common.candidates.get());
}
infos = ArrayUtils.addAll(infos, cacheInfos.get(common));
}
}
List<ItemStack> candidates = Arrays.stream(infos).filter(info -> info.getBlockState().getBlock() != Blocks.AIR).map(info -> {
IBlockState blockState = info.getBlockState();
MetaTileEntity metaTileEntity = info.getTileEntity() instanceof MetaTileEntityHolder ? ((MetaTileEntityHolder) info.getTileEntity()).getMetaTileEntity() : null;
if (metaTileEntity != null) {
return metaTileEntity.getStackForm();
} else {
return new ItemStack(Item.getItemFromBlock(blockState.getBlock()), 1, blockState.getBlock().damageDropped(blockState));
}
}).collect(Collectors.toList());
if (candidates.isEmpty())
continue;
// check inventory
ItemStack found = null;
if (!player.isCreative()) {
for (ItemStack itemStack : player.inventory.mainInventory) {
if (candidates.stream().anyMatch(candidate -> candidate.isItemEqual(itemStack)) && !itemStack.isEmpty() && itemStack.getItem() instanceof ItemBlock) {
found = itemStack.copy();
itemStack.setCount(itemStack.getCount() - 1);
break;
}
}
if (found == null)
continue;
} else {
for (int i = candidates.size() - 1; i >= 0; i--) {
found = candidates.get(i).copy();
if (!found.isEmpty() && found.getItem() instanceof ItemBlock) {
break;
}
found = null;
}
if (found == null)
continue;
}
ItemBlock itemBlock = (ItemBlock) found.getItem();
IBlockState state = itemBlock.getBlock().getStateFromMeta(itemBlock.getMetadata(found.getMetadata()));
blocks.put(pos, state);
world.setBlockState(pos, state);
TileEntity holder = world.getTileEntity(pos);
if (holder instanceof MetaTileEntityHolder) {
MetaTileEntity sampleMetaTileEntity = GregTechAPI.MTE_REGISTRY.getObjectById(found.getItemDamage());
if (sampleMetaTileEntity != null) {
MetaTileEntity metaTileEntity = ((MetaTileEntityHolder) holder).setMetaTileEntity(sampleMetaTileEntity);
blocks.put(pos, metaTileEntity);
if (found.hasTagCompound()) {
metaTileEntity.initFromItemStackData(found.getTagCompound());
}
}
}
}
}
}
z++;
}
}
// follow controller first
EnumFacing[] facings = ArrayUtils.addAll(new EnumFacing[] { controllerBase.getFrontFacing() }, FACINGS);
blocks.forEach((pos, block) -> {
// adjust facing
if (block instanceof MetaTileEntity) {
MetaTileEntity metaTileEntity = (MetaTileEntity) block;
boolean find = false;
for (EnumFacing enumFacing : facings) {
if (metaTileEntity.isValidFrontFacing(enumFacing)) {
if (!blocks.containsKey(pos.offset(enumFacing))) {
metaTileEntity.setFrontFacing(enumFacing);
find = true;
break;
}
}
}
if (!find) {
for (EnumFacing enumFacing : FACINGS) {
if (world.isAirBlock(pos.offset(enumFacing)) && metaTileEntity.isValidFrontFacing(enumFacing)) {
metaTileEntity.setFrontFacing(enumFacing);
break;
}
}
}
}
});
}
Aggregations