Fix AESU and Fusion control buttons

This commit is contained in:
modmuss50 2019-08-18 15:54:25 +01:00
parent 7f8bd2ab1f
commit 0bcf782f57
4 changed files with 35 additions and 32 deletions

View file

@ -68,29 +68,19 @@ public class AdjustableSUBlockEntity extends EnergyStorageBlockEntity implements
}
public void handleGuiInputFromClient(int id, boolean shift, boolean ctrl) {
if (id == 300) {
OUTPUT += shift ? 4096 : 256;
if(ctrl){
//Set to max, limited to the max later
OUTPUT = Integer.MAX_VALUE;
}
if(shift){
id *= 4;
}
if (id == 301) {
OUTPUT += shift ? 512 : 64;
}
if (id == 302) {
OUTPUT -= shift ? 512 : 64;
}
if (id == 303) {
OUTPUT -= shift ? 4096 : 256;
if(ctrl){
OUTPUT = 1;
}
if(ctrl){
id *= 8;
}
OUTPUT += id;
if (OUTPUT > getMaxConfigOutput()) {
OUTPUT = getMaxConfigOutput();
}
if (OUTPUT <= -1) {
if (OUTPUT <= 0) {
OUTPUT = 0;
}
}

View file

@ -25,6 +25,7 @@
package techreborn.client.gui;
import com.mojang.blaze3d.platform.GlStateManager;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.entity.player.PlayerEntity;
import reborncore.client.containerBuilder.builder.BuiltContainer;
@ -44,6 +45,12 @@ public class GuiAESU extends GuiBase<BuiltContainer> {
this.blockEntity = aesu;
}
@Override
public void init() {
super.init();
}
@Override
protected void drawBackground(final float f, final int mouseX, final int mouseY) {
super.drawBackground(f, mouseX, mouseY);
@ -52,7 +59,7 @@ public class GuiAESU extends GuiBase<BuiltContainer> {
this.drawSlot(62, 45, layer);
this.drawSlot(98, 45, layer);
this.drawArmourSlots(8, 18, layer);
this.builder.drawEnergyOutput(this, 171, 61, this.blockEntity.getCurrentOutput(), layer);
this.builder.drawEnergyOutput(this, 155, 61, this.blockEntity.getCurrentOutput(), layer);
this.builder.drawUpDownButtons(this, 121, 79, layer);
}
@ -71,14 +78,16 @@ public class GuiAESU extends GuiBase<BuiltContainer> {
}
builder.drawMultiEnergyBar(this, 81, 28, (int) blockEntity.getEnergy(), (int) blockEntity.getMaxPower(), mouseX, mouseY, 0, layer);
addButton(new GuiButtonUpDown(left + 121, top + 79, this, b -> onClick(256)));
addButton(new GuiButtonUpDown(left + 121 + 12, top + 79, this, b -> onClick(64)));
addButton(new GuiButtonUpDown(left + 121 + 24, top + 79, this, b -> onClick(-64)));
addButton(new GuiButtonUpDown(left + 121 + 36, top + 79, this, b -> onClick(-256)));
buttons.add(new GuiButtonUpDown(121, 79, this, layer, this::onClick));
buttons.add(new GuiButtonUpDown(121 + 12, 79, this, layer, this::onClick));
buttons.add(new GuiButtonUpDown(121 + 24, 79, this, layer, this::onClick));
buttons.add(new GuiButtonUpDown(121 + 36, 79, this, layer, this::onClick));
}
public void onClick(ButtonWidget button){
NetworkManager.sendToServer(ServerboundPackets.createPacketAesu(1, blockEntity));
public void onClick(int amount){
NetworkManager.sendToServer(ServerboundPackets.createPacketAesu(amount, Screen.hasShiftDown(), Screen.hasControlDown(), blockEntity));
}
}

View file

@ -72,7 +72,7 @@ public class GuiFusionReactor extends GuiBase<BuiltContainer> {
}
}
@Override
protected void drawForeground(final int mouseX, final int mouseY) {
super.drawForeground(mouseX, mouseY);
@ -105,10 +105,10 @@ public class GuiFusionReactor extends GuiBase<BuiltContainer> {
drawString("Size: " + blockEntity.size, 83, 81, 0xFFFFFF, layer);
drawString("" + blockEntity.getPowerMultiplier() + "x", 10, 81, 0xFFFFFF, layer);
buttons.add(new GuiButtonUpDown(121, 79, this, GuiBase.Layer.FOREGROUND, (ButtonWidget buttonWidget) -> sendSizeChange(5)));
buttons.add(new GuiButtonUpDown(121 + 12, 79, this, GuiBase.Layer.FOREGROUND, (ButtonWidget buttonWidget) -> sendSizeChange(1)));
buttons.add(new GuiButtonUpDown(121 + 24, 79, this, GuiBase.Layer.FOREGROUND, (ButtonWidget buttonWidget) -> sendSizeChange(-5)));
buttons.add(new GuiButtonUpDown(121 + 36, 79, this, GuiBase.Layer.FOREGROUND, (ButtonWidget buttonWidget) -> sendSizeChange(-1)));
addButton(new GuiButtonUpDown(left + 121, top + 79, this, (ButtonWidget buttonWidget) -> sendSizeChange(5)));
addButton(new GuiButtonUpDown(left + 121 + 12, top + 79, this, (ButtonWidget buttonWidget) -> sendSizeChange(1)));
addButton(new GuiButtonUpDown(left + 121 + 24, top + 79, this, (ButtonWidget buttonWidget) -> sendSizeChange(-5)));
addButton(new GuiButtonUpDown(left + 121 + 36, top + 79, this, (ButtonWidget buttonWidget) -> sendSizeChange(-1)));
builder.drawMultiEnergyBar(this, 9, 19, (int) this.blockEntity.getEnergy(), (int) this.blockEntity.getMaxPower(), mouseX, mouseY, 0, layer);
}

View file

@ -58,11 +58,13 @@ public class ServerboundPackets {
registerPacketHandler(AESU, (extendedPacketBuffer, context) -> {
BlockPos pos = extendedPacketBuffer.readBlockPos();
int buttonID = extendedPacketBuffer.readInt();
boolean shift = extendedPacketBuffer.readBoolean();
boolean ctrl = extendedPacketBuffer.readBoolean();
context.getTaskQueue().execute(() -> {
BlockEntity blockEntity = context.getPlayer().world.getBlockEntity(pos);
if (blockEntity instanceof AdjustableSUBlockEntity) {
((AdjustableSUBlockEntity) blockEntity).handleGuiInputFromClient(buttonID, false, false);
((AdjustableSUBlockEntity) blockEntity).handleGuiInputFromClient(buttonID, shift, ctrl);
}
});
});
@ -139,10 +141,12 @@ public class ServerboundPackets {
ServerSidePacketRegistry.INSTANCE.register(identifier, (packetContext, packetByteBuf) -> consumer.accept(new ExtendedPacketBuffer(packetByteBuf), packetContext));
}
public static Packet createPacketAesu(int buttonID, AdjustableSUBlockEntity blockEntity) {
public static Packet createPacketAesu(int buttonID, boolean shift, boolean ctrl, AdjustableSUBlockEntity blockEntity) {
return NetworkManager.createServerBoundPacket(AESU, extendedPacketBuffer -> {
extendedPacketBuffer.writeBlockPos(blockEntity.getPos());
extendedPacketBuffer.writeInt(buttonID);
extendedPacketBuffer.writeBoolean(shift);
extendedPacketBuffer.writeBoolean(ctrl);
});
}