Skip to content

Commit e45e26b

Browse files
committed
Further work on the BTA 7.3 update, focusing on MP too.
1 parent 5b77e78 commit e45e26b

Some content is hidden

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

42 files changed

+512
-98
lines changed

build.gradle

-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
plugins {
22
id 'fabric-loom' version '1.7.bta'
33
id 'java'
4-
id 'org.jetbrains.kotlin.jvm'
54
}
65

76
import org.gradle.internal.os.OperatingSystem
@@ -162,7 +161,3 @@ remapJar {
162161
destinationDirectory.set(file("$projectDir/jars"))
163162
archiveVersion.set(archiveVersion.get()+"-${bta_version}")
164163
}
165-
166-
kotlin {
167-
jvmToolchain(8)
168-
}

core/src/main/java/sunsetsatellite/catalyst/Catalyst.java

+40-35
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package sunsetsatellite.catalyst;
22

33
import net.fabricmc.api.ModInitializer;
4-
import net.minecraft.client.net.handler.PacketHandlerClient;
54
import net.minecraft.core.Global;
65
import net.minecraft.core.block.Block;
76
import net.minecraft.core.block.BlockLogic;
@@ -10,12 +9,11 @@
109
import net.minecraft.core.data.registry.Registry;
1110
import net.minecraft.core.entity.player.Player;
1211
import net.minecraft.core.item.ItemStack;
13-
import net.minecraft.core.net.packet.PacketDisconnect;
12+
import net.minecraft.core.net.packet.Packet;
1413
import net.minecraft.core.player.inventory.container.Container;
1514
import net.minecraft.core.util.collection.Pair;
1615
import net.minecraft.core.util.helper.MathHelper;
1716
import net.minecraft.core.util.helper.Side;
18-
import net.minecraft.core.util.phys.HitResult;
1917
import net.minecraft.core.world.World;
2018
import org.jetbrains.annotations.UnmodifiableView;
2119
import org.slf4j.Logger;
@@ -25,13 +23,13 @@
2523
import sunsetsatellite.catalyst.core.util.Signal;
2624
import sunsetsatellite.catalyst.core.util.mp.IMpGui;
2725
import sunsetsatellite.catalyst.core.util.mp.MpGuiEntry;
26+
import sunsetsatellite.catalyst.core.util.mp.PacketOpenGui;
2827
import sunsetsatellite.catalyst.core.util.network.NetworkManager;
2928
import sunsetsatellite.catalyst.core.util.section.BlockSection;
3029
import sunsetsatellite.catalyst.core.util.vector.Vec2f;
31-
import sunsetsatellite.catalyst.core.util.vector.Vec3f;
32-
import turniplabs.halplibe.helper.SoundHelper;
3330

3431
import java.util.*;
32+
import java.util.function.BiFunction;
3533

3634
public class Catalyst implements ModInitializer {
3735
public static final String MOD_ID = "catalyst-core";
@@ -46,9 +44,11 @@ public class Catalyst implements ModInitializer {
4644

4745
@Override
4846
public void onInitialize() {
47+
//todo: hardcoding bad
48+
Packet.addMapping(144,true,true, PacketOpenGui.class);
49+
4950
connectSignals();
5051
LOGGER.info("Catalyst: Core initialized.");
51-
5252
}
5353

5454
public void connectSignals() {
@@ -151,36 +151,32 @@ public static ArrayList<ItemStack> condenseItemList(List<ItemStack> list) {
151151
return condenseItemList(collectStacks(inv));
152152
}
153153

154-
public static Pair<Direction, BlockSection> getBlockSurfaceClickPosition(World world, Player player, HitResult hit){
154+
public static Pair<Direction, BlockSection> getBlockSurfaceClickPosition(World world, Player player, Side side, Vec2f clickPosition){
155155
if (!Global.isServer) {
156-
if(hit.hitType == HitResult.HitType.TILE){
157-
Direction dir = Direction.getDirectionFromSide(hit.side.getId());
158-
Vec3f vec3f = new Vec3f(hit.location.x,hit.location.y,hit.location.z);
159-
Vec2f clickPosition = vec3f.subtract(vec3f.copy().floor()).abs().set(hit.side.getAxis(),0).toVec2f();
160-
switch (hit.side) {
161-
case NORTH:
162-
clickPosition.x = 1-clickPosition.x;
163-
break;
164-
case EAST: {
165-
double temp1 = clickPosition.y;
166-
double temp2 = clickPosition.x;
167-
clickPosition.x = 1-temp1;
168-
clickPosition.y = temp2;
169-
break;
170-
}
171-
case SOUTH:
172-
//no change needed
173-
break;
174-
case WEST: {
175-
double temp1 = clickPosition.y;
176-
double temp2 = clickPosition.x;
177-
clickPosition.x = temp1;
178-
clickPosition.y = temp2;
179-
break;
180-
}
156+
Direction dir = Direction.getDirectionFromSide(side.getId());
157+
switch (side) {
158+
case NORTH:
159+
clickPosition.x = 1-clickPosition.x;
160+
break;
161+
case EAST: {
162+
double temp1 = clickPosition.y;
163+
double temp2 = clickPosition.x;
164+
clickPosition.x = 1-temp1;
165+
clickPosition.y = temp2;
166+
break;
167+
}
168+
case SOUTH:
169+
//no change needed
170+
break;
171+
case WEST: {
172+
double temp1 = clickPosition.y;
173+
double temp2 = clickPosition.x;
174+
clickPosition.x = temp1;
175+
clickPosition.y = temp2;
176+
break;
181177
}
182-
return Pair.of(dir,BlockSection.getClosestBlockSection(clickPosition));
183178
}
179+
return Pair.of(dir,BlockSection.getClosestBlockSection(clickPosition));
184180
}
185181
return null;
186182
}
@@ -190,12 +186,12 @@ public static Side calculatePlayerFacing(float rotation) {
190186
}
191187

192188
public static void displayGui(Player player, Container inventory, ItemStack stack){
193-
((IMpGui)player).displayCustomGUI(inventory,stack);
189+
((IMpGui)player).catalyst$displayCustomGUI(inventory,stack);
194190
}
195191

196192

197193
public static void displayGui(Player player, TileEntity tileEntity, String id){
198-
((IMpGui)player).displayCustomGUI(tileEntity, id);
194+
((IMpGui)player).catalyst$displayCustomGUI(tileEntity, id);
199195
}
200196

201197
public static <T> T blockLogic(Block<? extends BlockLogic> block, Class<T> clazz){
@@ -207,4 +203,13 @@ public static <T> T blockLogic(int id, Class<T> clazz){
207203
if(Block.hasLogicClass(Blocks.blocksList[id], clazz)) return (T) Blocks.blocksList[id].getLogic();
208204
else return null;
209205
}
206+
207+
public static <T> boolean listContains(List<T> list, T o, BiFunction<T,T,Boolean> equals){
208+
for (T obj : list) {
209+
if(equals.apply(o,obj)){
210+
return true;
211+
}
212+
}
213+
return false;
214+
}
210215
}

core/src/main/java/sunsetsatellite/catalyst/CatalystClient.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010
import net.minecraft.core.Global;
1111
import net.minecraft.core.item.Items;
1212
import sunsetsatellite.catalyst.core.util.mixin.interfaces.IKeybinds;
13-
import turniplabs.halplibe.util.GameStartEntrypoint;
13+
import turniplabs.halplibe.util.ClientStartEntrypoint;
1414

1515
@Environment(EnvType.CLIENT)
16-
public class CatalystClient implements GameStartEntrypoint {
16+
public class CatalystClient implements ClientStartEntrypoint {
1717

1818
public static OptionsPage optionsPage;
1919
public static OptionsCategory coreCategory;
@@ -24,12 +24,12 @@ public class CatalystClient implements GameStartEntrypoint {
2424
public static OptionsCategory multipartCategory;
2525

2626
@Override
27-
public void beforeGameStart() {
27+
public void beforeClientStart() {
2828

2929
}
3030

3131
@Override
32-
public void afterGameStart() {
32+
public void afterClientStart() {
3333
if(!Global.isServer){
3434
optionsPage = new OptionsPage("gui.options.page.catalyst", Items.DUST_REDSTONE.getDefaultStack());
3535
IKeybinds gameSettings = (IKeybinds) Minecraft.getMinecraft().gameSettings;

core/src/main/java/sunsetsatellite/catalyst/core/mixin/GuiTooltipMixin.java

+6-3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import net.minecraft.core.item.block.ItemBlock;
99
import net.minecraft.core.player.inventory.slot.Slot;
1010
import org.objectweb.asm.Opcodes;
11+
import org.spongepowered.asm.mixin.Debug;
1112
import org.spongepowered.asm.mixin.Mixin;
1213
import org.spongepowered.asm.mixin.Unique;
1314
import org.spongepowered.asm.mixin.injection.At;
@@ -26,24 +27,26 @@ public class GuiTooltipMixin extends Gui {
2627

2728
@Inject(
2829
method = "getTooltipText(Lnet/minecraft/core/item/ItemStack;ZLnet/minecraft/core/player/inventory/slot/Slot;)Ljava/lang/String;",
29-
at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/TooltipElement;formatDescription(Ljava/lang/String;I)Ljava/lang/String;",shift = At.Shift.AFTER)
30+
at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/TooltipElement;formatDescription(Ljava/lang/String;I)Ljava/lang/String;",shift = At.Shift.AFTER, ordinal = 0)
3031
)
3132
public void injectCustomTooltip(ItemStack itemStack, boolean showDescription, Slot slot, CallbackInfoReturnable<String> cir, @Local StringBuilder text) {
3233
addDescription(itemStack, text);
3334
}
3435

3536
@Inject(
3637
method = "getTooltipText(Lnet/minecraft/core/item/ItemStack;ZLnet/minecraft/core/player/inventory/slot/Slot;)Ljava/lang/String;",
37-
at = @At(value = "JUMP", opcode = Opcodes.IFEQ, ordinal = 12))
38+
at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/TooltipElement;formatDescription(Ljava/lang/String;I)Ljava/lang/String;",shift = At.Shift.AFTER, ordinal = 1)
39+
)
3840
public void injectPersistentTooltip(ItemStack itemStack, boolean showDescription, Slot slot, CallbackInfoReturnable<String> cir, @Local StringBuilder text){
39-
addDescription(itemStack, text);
41+
//addDescription(itemStack, text);
4042
}
4143

4244
@Unique
4345
private void addDescription(ItemStack itemStack, StringBuilder text) {
4446
if(itemStack != null && itemStack.getItem() instanceof ICustomDescription){
4547
if(!Objects.equals(((ICustomDescription) itemStack.getItem()).getDescription(itemStack), "")){
4648
text.append(((ICustomDescription) itemStack.getItem()).getDescription(itemStack)).append("\n");
49+
return;
4750
}
4851
}
4952

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package sunsetsatellite.catalyst.core.mixin;
2+
3+
import net.minecraft.client.Minecraft;
4+
import net.minecraft.client.gui.Screen;
5+
import net.minecraft.client.net.handler.PacketHandlerClient;
6+
import net.minecraft.client.world.WorldClientMP;
7+
import net.minecraft.core.block.entity.TileEntity;
8+
import net.minecraft.core.net.handler.PacketHandler;
9+
import org.spongepowered.asm.mixin.Final;
10+
import org.spongepowered.asm.mixin.Mixin;
11+
import org.spongepowered.asm.mixin.Shadow;
12+
import sunsetsatellite.catalyst.Catalyst;
13+
import sunsetsatellite.catalyst.core.util.mp.INetGuiHandler;
14+
import sunsetsatellite.catalyst.core.util.mp.MpGuiEntryClient;
15+
import sunsetsatellite.catalyst.core.util.mp.PacketOpenGui;
16+
17+
import java.lang.reflect.InvocationTargetException;
18+
import java.util.Objects;
19+
20+
@Mixin(value = PacketHandlerClient.class,remap = false)
21+
public class PacketHandlerClientMixin implements INetGuiHandler {
22+
@Shadow
23+
private WorldClientMP worldClientMP;
24+
25+
@Shadow
26+
@Final
27+
private Minecraft mc;
28+
29+
@Override
30+
public void catalyst$handleOpenGui(PacketOpenGui packet) {
31+
if(Objects.equals(packet.type, "tile")){
32+
TileEntity tile = worldClientMP.getTileEntity(packet.blockX,packet.blockY,packet.blockZ);
33+
if(tile != null){
34+
try {
35+
this.mc.displayScreen((Screen) ((MpGuiEntryClient) Catalyst.GUIS.getItem(packet.windowTitle)).guiClass.getDeclaredConstructors()[0].newInstance(this.mc.thePlayer.inventory,tile));
36+
} catch (InstantiationException | IllegalAccessException | InvocationTargetException e) {
37+
throw new RuntimeException(e);
38+
}
39+
}
40+
this.mc.thePlayer.craftingInventory.containerId = packet.windowId;
41+
} else if (Objects.equals(packet.type, "item")) {
42+
try {
43+
this.mc.displayScreen((Screen) ((MpGuiEntryClient) Catalyst.GUIS.getItem(packet.windowTitle)).guiClass.getDeclaredConstructors()[0].newInstance(this.mc.thePlayer.inventory,packet.stack));
44+
} catch (InstantiationException | IllegalAccessException | InvocationTargetException e) {
45+
throw new RuntimeException(e);
46+
}
47+
}
48+
}
49+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package sunsetsatellite.catalyst.core.mixin;
2+
3+
import net.minecraft.client.Minecraft;
4+
import net.minecraft.client.entity.player.PlayerLocal;
5+
import net.minecraft.client.gui.Screen;
6+
import net.minecraft.core.block.entity.TileEntity;
7+
import net.minecraft.core.item.ItemStack;
8+
import net.minecraft.core.player.inventory.container.Container;
9+
import org.spongepowered.asm.mixin.Mixin;
10+
import org.spongepowered.asm.mixin.Shadow;
11+
import sunsetsatellite.catalyst.Catalyst;
12+
import sunsetsatellite.catalyst.core.util.mp.IMpGui;
13+
import sunsetsatellite.catalyst.core.util.mp.MpGuiEntryClient;
14+
15+
import java.lang.reflect.InvocationTargetException;
16+
17+
@Mixin(value = PlayerLocal.class,remap = false)
18+
public class PlayerLocalMixin implements IMpGui {
19+
20+
@Shadow
21+
protected Minecraft mc;
22+
23+
@Override
24+
public void catalyst$displayCustomGUI(Container inventory, ItemStack stack) {
25+
MpGuiEntryClient entry = (MpGuiEntryClient) Catalyst.GUIS.getItem(inventory.getNameTranslationKey());
26+
try {
27+
mc.displayScreen((Screen) entry.guiClass.getDeclaredConstructors()[0].newInstance(this.mc.thePlayer.inventory,inventory));
28+
} catch (InstantiationException | IllegalAccessException | InvocationTargetException e) {
29+
throw new RuntimeException(e);
30+
}
31+
}
32+
33+
@Override
34+
public void catalyst$displayCustomGUI(TileEntity tileEntity, String id) {
35+
MpGuiEntryClient entry = (MpGuiEntryClient) Catalyst.GUIS.getItem(id);
36+
try {
37+
mc.displayScreen((Screen) entry.guiClass.getDeclaredConstructors()[0].newInstance(this.mc.thePlayer.inventory,tileEntity));
38+
} catch (InstantiationException | IllegalAccessException | InvocationTargetException e) {
39+
throw new RuntimeException(e);
40+
}
41+
}
42+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package sunsetsatellite.catalyst.core.mixin;
2+
3+
import net.minecraft.core.entity.player.Player;
4+
import org.spongepowered.asm.mixin.Mixin;
5+
import sunsetsatellite.catalyst.core.util.mp.IMpGui;
6+
7+
@Mixin(value = Player.class,remap = false)
8+
public abstract class PlayerMixin implements IMpGui {
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
package sunsetsatellite.catalyst.core.mixin;
2+
3+
import net.minecraft.core.block.entity.TileEntity;
4+
import net.minecraft.core.entity.player.Player;
5+
import net.minecraft.core.item.ItemStack;
6+
import net.minecraft.core.player.inventory.container.Container;
7+
import net.minecraft.core.player.inventory.menu.MenuAbstract;
8+
import net.minecraft.core.world.World;
9+
import net.minecraft.server.entity.player.PlayerServer;
10+
import net.minecraft.server.net.handler.PacketHandlerServer;
11+
import org.spongepowered.asm.mixin.Mixin;
12+
import org.spongepowered.asm.mixin.Shadow;
13+
import org.spongepowered.asm.mixin.Unique;
14+
import sunsetsatellite.catalyst.Catalyst;
15+
import sunsetsatellite.catalyst.core.util.mp.IMpGui;
16+
import sunsetsatellite.catalyst.core.util.mp.MpGuiEntry;
17+
import sunsetsatellite.catalyst.core.util.mp.PacketOpenGui;
18+
19+
import java.lang.reflect.InvocationTargetException;
20+
21+
@Mixin(value = PlayerServer.class,remap = false)
22+
public abstract class PlayerServerMixin extends Player implements IMpGui {
23+
24+
private PlayerServerMixin(World world) {
25+
super(world);
26+
}
27+
28+
@Shadow
29+
protected abstract void getNextWindowId();
30+
31+
@Shadow
32+
private int currentWindowId;
33+
@Shadow
34+
public PacketHandlerServer playerNetServerHandler;
35+
@Unique
36+
private final PlayerServer thisAs = (PlayerServer)(Object)this;
37+
38+
//TODO: change display methods to have xyz argument and stack argument
39+
40+
@Override
41+
public void catalyst$displayCustomGUI(Container inventory, ItemStack stack) {
42+
this.getNextWindowId();
43+
MpGuiEntry entry = Catalyst.GUIS.getItem(inventory.getNameTranslationKey());
44+
this.playerNetServerHandler.sendPacket(new PacketOpenGui(this.currentWindowId, inventory.getNameTranslationKey(),stack));
45+
if(entry.containerClass != null) {
46+
try {
47+
this.craftingInventory = (MenuAbstract) entry.containerClass.getDeclaredConstructors()[0].newInstance(thisAs.inventory, inventory);
48+
} catch (InstantiationException | IllegalAccessException | InvocationTargetException e) {
49+
throw new RuntimeException(e);
50+
}
51+
this.craftingInventory.containerId = this.currentWindowId;
52+
this.craftingInventory.addSlotListener(thisAs);
53+
}
54+
55+
}
56+
57+
@Override
58+
public void catalyst$displayCustomGUI(TileEntity tileEntity, String id) {
59+
this.getNextWindowId();
60+
MpGuiEntry entry = Catalyst.GUIS.getItem(id);
61+
this.playerNetServerHandler.sendPacket(new PacketOpenGui(this.currentWindowId, id, tileEntity.x, tileEntity.y, tileEntity.z));
62+
if(entry.containerClass != null){
63+
try {
64+
this.craftingInventory = (MenuAbstract) entry.containerClass.getDeclaredConstructors()[0].newInstance(thisAs.inventory, tileEntity);
65+
} catch (InstantiationException | IllegalAccessException | InvocationTargetException e) {
66+
throw new RuntimeException(e);
67+
}
68+
this.craftingInventory.containerId = this.currentWindowId;
69+
this.craftingInventory.addSlotListener(thisAs);
70+
}
71+
}
72+
}

0 commit comments

Comments
 (0)