Skip to content

Commit 89ab435

Browse files
committed
Parallel recipe process; Fix #9.
1 parent d5efa18 commit 89ab435

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+677
-186
lines changed

src/main/java/github/kasuminova/mmce/common/event/EventHandler.java

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,16 @@
33
import hellfirepvp.modularmachinery.common.container.ContainerBase;
44
import hellfirepvp.modularmachinery.common.data.Config;
55
import hellfirepvp.modularmachinery.common.tiles.base.SelectiveUpdateTileEntity;
6+
import net.minecraft.client.entity.EntityPlayerSP;
7+
import net.minecraft.entity.player.EntityPlayer;
68
import net.minecraft.entity.player.EntityPlayerMP;
9+
import net.minecraft.network.play.server.SPacketUpdateTileEntity;
710
import net.minecraft.tileentity.TileEntity;
811
import net.minecraft.world.World;
912
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
1013
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
1114
import net.minecraftforge.fml.common.gameevent.TickEvent;
1215
import net.minecraftforge.fml.relauncher.Side;
13-
import net.minecraftforge.fml.relauncher.SideOnly;
1416

1517
public class EventHandler {
1618
/**
@@ -19,17 +21,21 @@ public class EventHandler {
1921
* Avoid the problem of some messages being out of sync.</p>
2022
*/
2123
@SubscribeEvent
22-
@SideOnly(Side.SERVER)
2324
public void onPlayerRightClickBlock(PlayerInteractEvent.RightClickBlock event) {
2425
World world = event.getWorld();
25-
if (Config.selectiveUpdateTileEntity || !(event.getEntityPlayer() instanceof EntityPlayerMP)) {
26+
if (Config.selectiveUpdateTileEntity || world.isRemote) {
2627
return;
2728
}
2829

2930
TileEntity te = world.getTileEntity(event.getPos());
30-
EntityPlayerMP player = (EntityPlayerMP) event.getEntityPlayer();
31-
if (te instanceof SelectiveUpdateTileEntity) {
32-
player.connection.sendPacket(((SelectiveUpdateTileEntity) te).getTrueUpdatePacket());
31+
if (!(te instanceof SelectiveUpdateTileEntity)) {
32+
return;
33+
}
34+
SPacketUpdateTileEntity packet = ((SelectiveUpdateTileEntity) te).getTrueUpdatePacket();
35+
if (event.getEntityPlayer() instanceof EntityPlayerSP) {
36+
((EntityPlayerSP) event.getEntityPlayer()).connection.sendPacket(packet);
37+
} else if (event.getEntityPlayer() instanceof EntityPlayerMP) {
38+
((EntityPlayerMP) event.getEntityPlayer()).connection.sendPacket(packet);
3339
}
3440
}
3541

@@ -38,18 +44,25 @@ public void onPlayerRightClickBlock(PlayerInteractEvent.RightClickBlock event) {
3844
* <p>Provide selective updates for certain square entities that tend to consume a lot of bandwidth to relieve network pressure.</p>
3945
*/
4046
@SubscribeEvent
41-
@SideOnly(Side.SERVER)
4247
public void onPlayerTick(TickEvent.PlayerTickEvent event) {
43-
if (event.phase != TickEvent.Phase.START || !Config.selectiveUpdateTileEntity || !(event.player instanceof EntityPlayerMP)) {
48+
if (event.phase != TickEvent.Phase.START || !Config.selectiveUpdateTileEntity || event.side == Side.CLIENT) {
49+
return;
50+
}
51+
52+
EntityPlayer player = event.player;
53+
if (!(player.openContainer instanceof ContainerBase)) {
54+
return;
55+
}
56+
TileEntity te = ((ContainerBase<?>) player.openContainer).getOwner();
57+
if (!(te instanceof SelectiveUpdateTileEntity)) {
4458
return;
4559
}
60+
SPacketUpdateTileEntity packet = ((SelectiveUpdateTileEntity) te).getTrueUpdatePacket();
4661

47-
EntityPlayerMP player = (EntityPlayerMP) event.player;
48-
if (player.openContainer instanceof ContainerBase) {
49-
TileEntity te = ((ContainerBase<?>) player.openContainer).getOwner();
50-
if (te instanceof SelectiveUpdateTileEntity) {
51-
player.connection.sendPacket(((SelectiveUpdateTileEntity) te).getTrueUpdatePacket());
52-
}
62+
if (event.player instanceof EntityPlayerSP) {
63+
((EntityPlayerSP) event.player).connection.sendPacket(packet);
64+
} else if (event.player instanceof EntityPlayerMP) {
65+
((EntityPlayerMP) event.player).connection.sendPacket(packet);
5366
}
5467
}
5568
}

src/main/java/hellfirepvp/modularmachinery/ModularMachinery.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,7 @@
1313
import hellfirepvp.modularmachinery.common.command.CommandHand;
1414
import hellfirepvp.modularmachinery.common.command.CommandPerformanceReport;
1515
import hellfirepvp.modularmachinery.common.command.CommandSyntax;
16-
import hellfirepvp.modularmachinery.common.network.PktCopyToClipboard;
17-
import hellfirepvp.modularmachinery.common.network.PktInteractFluidTankGui;
18-
import hellfirepvp.modularmachinery.common.network.PktSmartInterfaceUpdate;
19-
import hellfirepvp.modularmachinery.common.network.PktSyncSelection;
16+
import hellfirepvp.modularmachinery.common.network.*;
2017
import net.minecraft.launchwrapper.Launch;
2118
import net.minecraftforge.fluids.FluidRegistry;
2219
import net.minecraftforge.fml.common.Mod;
@@ -78,6 +75,7 @@ public void preInit(FMLPreInitializationEvent event) {
7875

7976
NET_CHANNEL.registerMessage(PktInteractFluidTankGui.class, PktInteractFluidTankGui.class, 2, Side.SERVER);
8077
NET_CHANNEL.registerMessage(PktSmartInterfaceUpdate.class, PktSmartInterfaceUpdate.class, 3, Side.SERVER);
78+
NET_CHANNEL.registerMessage(PktParallelControllerUpdate.class, PktParallelControllerUpdate.class, 4, Side.SERVER);
8179

8280
proxy.loadModData(event.getModConfigurationDirectory());
8381

src/main/java/hellfirepvp/modularmachinery/client/gui/GuiContainerParallelController.java

Lines changed: 152 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,36 @@
11
package hellfirepvp.modularmachinery.client.gui;
22

3+
import hellfirepvp.modularmachinery.ModularMachinery;
34
import hellfirepvp.modularmachinery.common.container.ContainerParallelController;
5+
import hellfirepvp.modularmachinery.common.network.PktParallelControllerUpdate;
46
import hellfirepvp.modularmachinery.common.tiles.TileParallelController;
7+
import hellfirepvp.modularmachinery.common.util.MiscUtils;
58
import net.minecraft.client.Minecraft;
9+
import net.minecraft.client.audio.SoundHandler;
10+
import net.minecraft.client.gui.FontRenderer;
611
import net.minecraft.client.gui.GuiButton;
712
import net.minecraft.client.gui.GuiTextField;
813
import net.minecraft.client.renderer.GlStateManager;
14+
import net.minecraft.client.resources.I18n;
915
import net.minecraft.entity.player.EntityPlayer;
1016
import net.minecraftforge.client.model.animation.Animation;
17+
import org.lwjgl.input.Keyboard;
1118

19+
import java.io.IOException;
1220
import java.util.ArrayList;
1321
import java.util.List;
1422

1523
public class GuiContainerParallelController extends GuiContainerBase<ContainerParallelController> {
1624
private final TileParallelController parallelCtrlInterface;
17-
private List<GuiButton> buttons = new ArrayList<>();
25+
private final List<GuiButton> buttons = new ArrayList<>();
1826
private GuiButton increment_1;
1927
private GuiButton increment_10;
2028
private GuiButton increment_100;
2129
private GuiButton decrement_1;
2230
private GuiButton decrement_10;
2331
private GuiButton decrement_100;
2432
private GuiTextField textField;
33+
2534
public GuiContainerParallelController(TileParallelController te, EntityPlayer opening) {
2635
super(new ContainerParallelController(te, opening));
2736
this.parallelCtrlInterface = te;
@@ -30,7 +39,24 @@ public GuiContainerParallelController(TileParallelController te, EntityPlayer op
3039
@Override
3140
protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) {
3241
super.drawGuiContainerForegroundLayer(mouseX, mouseY);
42+
GlStateManager.pushMatrix();
43+
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
44+
45+
int offsetX = 4;
46+
int offsetY = 4;
47+
FontRenderer fr = this.fontRenderer;
48+
fr.drawStringWithShadow(I18n.format("gui.parallelcontroller.title"), offsetX, offsetY, 0xFFFFFF);
49+
offsetX += 2;
50+
offsetY += 12;
51+
52+
TileParallelController.ParallelControllerProvider provider = parallelCtrlInterface.provideComponent();
3353

54+
fr.drawStringWithShadow(I18n.format("gui.parallelcontroller.max_value", provider.getMaxParallelism()), offsetX, offsetY, 0xFFFFFF);
55+
offsetY += 33;
56+
fr.drawStringWithShadow(I18n.format("gui.parallelcontroller.current_value", provider.getParallelism()), offsetX, offsetY, 0xFFFFFF);
57+
58+
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
59+
GlStateManager.popMatrix();
3460
}
3561

3662
@Override
@@ -53,29 +79,146 @@ protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, i
5379
}
5480
}
5581

82+
@Override
83+
protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException {
84+
super.mouseClicked(mouseX, mouseY, mouseButton);
85+
if (mouseButton != 0) {
86+
return;
87+
}
88+
89+
boolean clicked = textField.mouseClicked(mouseX, mouseY, mouseButton);
90+
if (clicked) {
91+
return;
92+
}
93+
94+
Minecraft mc = Minecraft.getMinecraft();
95+
SoundHandler soundHandler = mc.getSoundHandler();
96+
97+
TileParallelController.ParallelControllerProvider provider = parallelCtrlInterface.provideComponent();
98+
int parallelism = provider.getParallelism();
99+
int maxParallelism = provider.getMaxParallelism();
100+
int maxCanIncrement = maxParallelism - parallelism;
101+
102+
if (increment_1.mousePressed(mc, mouseX, mouseY)) {
103+
if (maxCanIncrement >= 1) {
104+
ModularMachinery.NET_CHANNEL.sendToServer(
105+
new PktParallelControllerUpdate(parallelism + 1)
106+
);
107+
}
108+
increment_1.playPressSound(soundHandler);
109+
return;
110+
}
111+
if (increment_10.mousePressed(mc, mouseX, mouseY)) {
112+
if (maxCanIncrement >= 10) {
113+
ModularMachinery.NET_CHANNEL.sendToServer(
114+
new PktParallelControllerUpdate(parallelism + 10)
115+
);
116+
} else {
117+
ModularMachinery.NET_CHANNEL.sendToServer(
118+
new PktParallelControllerUpdate(maxParallelism)
119+
);
120+
}
121+
increment_10.playPressSound(soundHandler);
122+
return;
123+
}
124+
if (increment_100.mousePressed(mc, mouseX, mouseY)) {
125+
if (maxCanIncrement >= 100) {
126+
ModularMachinery.NET_CHANNEL.sendToServer(
127+
new PktParallelControllerUpdate(parallelism + 100)
128+
);
129+
} else {
130+
ModularMachinery.NET_CHANNEL.sendToServer(
131+
new PktParallelControllerUpdate(maxParallelism)
132+
);
133+
}
134+
increment_100.playPressSound(soundHandler);
135+
return;
136+
}
137+
int maxCanDecrement = Math.max(0, parallelism - 1);
138+
if (decrement_1.mousePressed(mc, mouseX, mouseY)) {
139+
if (maxCanDecrement >= 1) {
140+
ModularMachinery.NET_CHANNEL.sendToServer(
141+
new PktParallelControllerUpdate(parallelism - 1)
142+
);
143+
}
144+
decrement_1.playPressSound(soundHandler);
145+
return;
146+
}
147+
if (decrement_10.mousePressed(mc, mouseX, mouseY)) {
148+
if (maxCanDecrement >= 10) {
149+
ModularMachinery.NET_CHANNEL.sendToServer(
150+
new PktParallelControllerUpdate(parallelism - 10)
151+
);
152+
} else {
153+
ModularMachinery.NET_CHANNEL.sendToServer(
154+
new PktParallelControllerUpdate(1)
155+
);
156+
}
157+
decrement_10.playPressSound(soundHandler);
158+
return;
159+
}
160+
if (decrement_100.mousePressed(mc, mouseX, mouseY)) {
161+
if (maxCanDecrement >= 100) {
162+
ModularMachinery.NET_CHANNEL.sendToServer(
163+
new PktParallelControllerUpdate(parallelism - 100)
164+
);
165+
} else {
166+
ModularMachinery.NET_CHANNEL.sendToServer(
167+
new PktParallelControllerUpdate(1)
168+
);
169+
}
170+
decrement_100.playPressSound(soundHandler);
171+
}
172+
}
173+
174+
@Override
175+
public void keyTyped(char c, int i) throws IOException {
176+
if (!textField.isFocused()) {
177+
super.keyTyped(c, i);
178+
}
179+
180+
if (i == Keyboard.KEY_RETURN) {
181+
TileParallelController.ParallelControllerProvider provider = parallelCtrlInterface.provideComponent();
182+
183+
try {
184+
int newParallelism = Integer.parseInt(textField.getText());
185+
if (newParallelism < provider.getMaxParallelism() && newParallelism > 0) {
186+
ModularMachinery.NET_CHANNEL.sendToServer(new PktParallelControllerUpdate(newParallelism));
187+
}
188+
textField.setText("");
189+
} catch (NumberFormatException ignored) {
190+
}
191+
return;
192+
}
193+
194+
if (Character.isDigit(c) || MiscUtils.isTextBoxKey(i)) {
195+
textField.textboxKeyTyped(c, i);
196+
}
197+
}
198+
56199
@Override
57200
public void initGui() {
58201
super.initGui();
59-
textField = new GuiTextField(0, fontRenderer, 10, this.height / 2 - 48, 160, 10);
60-
textField.setMaxStringLength(16);
202+
textField = new GuiTextField(0, fontRenderer, this.width / 2 - 15, this.height / 2 - 35, 95, 10);
203+
textField.setMaxStringLength(10);
61204

62-
decrement_1 = new GuiButton(1, this.width / 2 - 81, this.height / 2 + 25, 20, 20,
205+
decrement_1 = new GuiButton(1, this.width / 2 - 81, this.height / 2 - 57, 30, 20,
63206
"-1");
64207
buttons.add(decrement_1);
65-
decrement_10 = new GuiButton(2, this.width / 2 - 51, this.height / 2 + 25, 30, 20,
208+
decrement_10 = new GuiButton(2, this.width / 2 - 16, this.height / 2 - 57, 30, 20,
66209
"-10");
67210
buttons.add(decrement_10);
68-
decrement_100 = new GuiButton(3, this.width / 2 - 1, this.height / 2 + 25, 40, 20,
211+
decrement_100 = new GuiButton(3, this.width / 2 + 51, this.height / 2 - 57, 30, 20,
69212
"-100");
70213
buttons.add(decrement_100);
71214

72-
increment_1 = new GuiButton(4, this.width / 2 - 81, this.height / 2 - 25, 20, 20,
215+
increment_1 = new GuiButton(4, this.width / 2 - 81, this.height / 2 - 23, 30, 20,
73216
"+1");
74217
buttons.add(increment_1);
75-
increment_10 = new GuiButton(5, this.width / 2 - 51, this.height / 2 - 25, 30, 20,
218+
increment_10 = new GuiButton(5, this.width / 2 - 16, this.height / 2 - 23, 30, 20,
76219
"+10");
77220
buttons.add(increment_10);
78-
increment_100 = new GuiButton(6, this.width / 2 - 1, this.height / 2 - 25, 40, 20,
221+
increment_100 = new GuiButton(6, this.width / 2 + 51, this.height / 2 - 23, 30, 20,
79222
"+100");
80223
buttons.add(increment_100);
81224
}

src/main/java/hellfirepvp/modularmachinery/client/gui/GuiContainerSmartInterface.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) {
5454
int offsetY = 4;
5555
FontRenderer fr = this.fontRenderer;
5656
fr.drawStringWithShadow(I18n.format("gui.smartinterface.title", component.getBoundSize(), showing + 1), offsetX, offsetY, 0xFFFFFF);
57-
offsetX += 4;
57+
offsetX += 3;
5858
offsetY += 12;
5959

6060
SmartInterfaceData data = component.getMachineData(showing);

src/main/java/hellfirepvp/modularmachinery/client/gui/GuiMachineController.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,13 +144,26 @@ protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) {
144144
fr.drawStringWithShadow(draw, offsetX, offsetY, 0xFFFFFF);
145145
}
146146
offsetY += 15;
147-
if (controller.hasActiveRecipe()) {
148-
ActiveMachineRecipe activeRecipe = controller.getActiveRecipe();
147+
148+
ActiveMachineRecipe activeRecipe = controller.getActiveRecipe();
149+
if (activeRecipe != null) {
149150
if (activeRecipe.getTotalTick() > 0) {
150151
int progress = (activeRecipe.getTick() * 100) / activeRecipe.getTotalTick();
151152
String progressStr = I18n.format("gui.controller.status.crafting.progress", progress + "%");
152153
fr.drawStringWithShadow(progressStr, offsetX, offsetY, 0xFFFFFF);
153154
}
155+
int parallelism = activeRecipe.getParallelism();
156+
if (parallelism > 1) {
157+
offsetY += 10;
158+
String parallelismStr = I18n.format("gui.controller.parallelism", parallelism);
159+
fr.drawStringWithShadow(parallelismStr, offsetX, offsetY, 0xFFFFFF);
160+
}
161+
int maxParallelism = activeRecipe.getMaxParallelism();
162+
if (maxParallelism > 1) {
163+
offsetY += 10;
164+
String maxParallelismStr = I18n.format("gui.controller.max_parallelism", maxParallelism);
165+
fr.drawStringWithShadow(maxParallelismStr, offsetX, offsetY, 0xFFFFFF);
166+
}
154167
}
155168

156169
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);

src/main/java/hellfirepvp/modularmachinery/client/gui/GuiScreenBlueprint.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ public void drawScreen(int mouseX, int mouseY, float partialTicks) {
177177
}
178178

179179
fontRenderer.drawStringWithShadow(machine.getLocalizedName(), this.guiLeft + 10, this.guiTop + 11, 0xFFFFFFFF);
180-
if (machine.requiresBlueprint()) {
180+
if (machine.isRequiresBlueprint()) {
181181
String reqBlueprint = I18n.format("tooltip.machinery.blueprint.required");
182182
fontRenderer.drawStringWithShadow(reqBlueprint, this.guiLeft + 10, this.guiTop + 106, 0xFFFFFF);
183183
}

src/main/java/hellfirepvp/modularmachinery/client/util/RenderingUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public class RenderingUtils {
3838
static void drawWhiteOutlineCubes(List<BlockPos> positions, float partialTicks) {
3939
GlStateManager.enableBlend();
4040
GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
41-
GlStateManager.color(1F, 1F, 1F, 0.1F);
41+
GlStateManager.color(1F, 1F, 1F, 0.4F);
4242
GlStateManager.disableTexture2D();
4343
GlStateManager.enableColorMaterial();
4444
GlStateManager.disableCull();

0 commit comments

Comments
 (0)