Skip to content

Commit 48df5ce

Browse files
Ported to 1.19, refactor
Straight port to 1.19 feature-wise Refactored the code; all classes which other mods should ever directly import are now in the 'api' package, rather than having them spread out everywhere.
1 parent 300f9c8 commit 48df5ce

File tree

133 files changed

+1057
-975
lines changed

Some content is hidden

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

133 files changed

+1057
-975
lines changed

build.gradle

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,10 @@ dependencies {
8787

8888
//JEI
8989
//Compile against APIs
90-
compileOnly fg.deobf("mezz.jei:jei-$jei_mc_version:$jei_version:api")
90+
compileOnly fg.deobf("mezz.jei:jei-$jei_mc_version-common-api:$jei_version")
91+
compileOnly fg.deobf("mezz.jei:jei-$jei_mc_version-forge-api:$jei_version")
9192
//Run with the full versions
92-
runtimeOnly fg.deobf("mezz.jei:jei-$jei_mc_version:$jei_version")
93+
runtimeOnly fg.deobf("mezz.jei:jei-$jei_mc_version-forge:$jei_version")
9394
//Patchouli
9495
compileOnly(fg.deobf("vazkii.patchouli:Patchouli:$patchouli_version"))
9596
runtimeOnly(fg.deobf("vazkii.patchouli:Patchouli:$patchouli_version"))

gradle.properties

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
# This is required to provide enough memory for the Minecraft decompilation process.
33
org.gradle.jvmargs=-Xmx3G
44
org.gradle.daemon=false
5-
mod_version=2.14.0
6-
mc_version=1.18.2
7-
fg_version=40.1.20
5+
mod_version=2.15.0
6+
mc_version=1.19
7+
fg_version=41.0.45
88
mcp_channel=official
9-
mcp_version=1.18.2
10-
jei_mc_version=1.18.2
11-
jei_version=9.5.0.132
12-
patchouli_version=1.18.2-66
13-
cctweaked_version=1.100.5
9+
mcp_version=1.19
10+
jei_mc_version=1.19
11+
jei_version=11.0.0.206
12+
patchouli_version=1.19-73
13+
cctweaked_version=1.100.8
Lines changed: 3 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,23 @@
11
package com.Da_Technomancer.essentials;
22

3+
import com.Da_Technomancer.essentials.api.ConfigUtil;
34
import com.electronwill.nightconfig.core.file.CommentedFileConfig;
45
import com.electronwill.nightconfig.core.io.WritingMode;
5-
import net.minecraft.ChatFormatting;
6-
import net.minecraft.network.chat.Style;
7-
import net.minecraft.resources.ResourceLocation;
8-
import net.minecraft.tags.ItemTags;
9-
import net.minecraft.tags.TagKey;
10-
import net.minecraft.world.item.Item;
11-
import net.minecraft.world.item.ItemStack;
126
import net.minecraftforge.common.ForgeConfigSpec;
13-
import net.minecraftforge.common.ToolAction;
147
import net.minecraftforge.fml.ModLoadingContext;
158
import net.minecraftforge.fml.config.ModConfig;
169
import net.minecraftforge.fml.loading.FMLPaths;
1710

18-
import javax.annotation.Nullable;
19-
import java.text.DecimalFormat;
20-
import java.text.NumberFormat;
21-
2211
public class ESConfig{
2312

24-
/**
25-
* A common style applied to "quip" lines in tooltips
26-
*/
27-
public static final Style TT_QUIP = Style.EMPTY.applyFormat(ChatFormatting.AQUA).withItalic(true);
28-
2913
public static ForgeConfigSpec.BooleanValue addWrench;
3014

3115
// private static ForgeConfigSpec.ConfigValue<List<? extends String>> wrenchTypes;
3216
public static ForgeConfigSpec.IntValue brazierRange;
3317
public static ForgeConfigSpec.IntValue itemChuteRange;
3418
public static ForgeConfigSpec.DoubleValue fertileSoilRate;
3519
public static ForgeConfigSpec.IntValue maxRedstoneRange;
36-
public static ForgeConfigSpec.EnumValue<NumberTypes> numberDisplay;
20+
public static ForgeConfigSpec.EnumValue<ConfigUtil.NumberTypes> numberDisplay;
3721
public static ForgeConfigSpec.IntValue wirelessRange;
3822

3923
private static ForgeConfigSpec clientSpec;
@@ -43,7 +27,7 @@ protected static void init(){
4327
//Client config
4428
ForgeConfigSpec.Builder clientBuilder = new ForgeConfigSpec.Builder();
4529
addWrench = clientBuilder.worldRestart().comment("Should the Wrench show up in the creative menu?").define("creative_wrench", true);
46-
numberDisplay = clientBuilder.comment("How should very large and small numbers be displayed?", "Options are: NORMAL, SCIENTIFIC, ENGINEERING, and HEX").defineEnum("num_display", NumberTypes.SCIENTIFIC);
30+
numberDisplay = clientBuilder.comment("How should very large and small numbers be displayed?", "Options are: NORMAL, SCIENTIFIC, ENGINEERING, and HEX").defineEnum("num_display", ConfigUtil.NumberTypes.SCIENTIFIC);
4731

4832
clientSpec = clientBuilder.build();
4933
ModLoadingContext.get().registerConfig(ModConfig.Type.CLIENT, clientSpec);
@@ -71,75 +55,4 @@ protected static void load(){
7155
serverSpec.setConfig(serverConfig);
7256
}
7357

74-
private static final TagKey<Item> WRENCH = ItemTags.create(new ResourceLocation("forge:wrench"));
75-
public static final ToolAction WRENCH_ACTION = ToolAction.get("wrench");//No single standard for wrench tool action name has emerged yet
76-
77-
/**
78-
* @param stack The stack to test
79-
* @return Whether this item is considered a wrench
80-
*/
81-
public static boolean isWrench(ItemStack stack){
82-
//Essentials prefers wrenches defined via the forge:item/wrench.json, but will also check tool actions- which some mods use to define their wrench
83-
return stack.is(WRENCH) || stack.canPerformAction(WRENCH_ACTION);
84-
}
85-
86-
/**
87-
* Formats floating point values for display
88-
* @param value The value to format
89-
* @param format The format to conform the value to. Uses the value in the config if null.
90-
* @return The formatted string version, for display
91-
*/
92-
public static String formatFloat(float value, @Nullable NumberTypes format){
93-
if(format == null){
94-
format = numberDisplay.get();
95-
}
96-
switch(format){
97-
case SCIENTIFIC:
98-
float absValue = Math.abs(value);
99-
if(absValue == 0){
100-
return "0";
101-
}
102-
if(absValue < 1000 && absValue >= 0.0005F){
103-
return trimTrail(Math.round(value * 1000F) / 1000F);
104-
}
105-
106-
return scientific.format(value);
107-
case ENGINEERING:
108-
float absoValue = Math.abs(value);
109-
if(absoValue == 0){
110-
return "0";
111-
}
112-
if(absoValue < 1000 && absoValue >= 0.0005F){
113-
return trimTrail(Math.round(value * 1000F) / 1000F);
114-
}
115-
116-
return engineering.format(value);
117-
case HEX:
118-
//This option exists mainly for debugging. It shows the entire hex definition of the float value
119-
return Float.toHexString(value);
120-
case NORMAL:
121-
default:
122-
return Float.toString(value);
123-
}
124-
}
125-
126-
private static String trimTrail(float valFloat){
127-
String val = Float.toString(valFloat);
128-
//Removes the .0 java appends to string representations of integer-valued floats
129-
while(val.contains(".") && (val.endsWith("0") || val.endsWith("."))){
130-
val = val.substring(0, val.length() - 2);
131-
}
132-
return val;
133-
}
134-
135-
private static final NumberFormat scientific = new DecimalFormat("0.###E0");
136-
private static final NumberFormat engineering = new DecimalFormat("##0.###E0");
137-
138-
public enum NumberTypes{
139-
140-
NORMAL(),//Java default
141-
SCIENTIFIC(),//Scientific notation when magnitude outside of 0.001-1000
142-
ENGINEERING(),//Engineering notation when magnitude outside of 0.001-1000
143-
HEX()//Display the raw float hexadecimal. This exists mainly for debugging. You want this? WHAT IS WRONG WITH YOU?
144-
}
14558
}

src/main/java/com/Da_Technomancer/essentials/ESEventHandlerClient.java

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
package com.Da_Technomancer.essentials;
22

3-
import com.Da_Technomancer.essentials.blocks.BlockUtil;
3+
import com.Da_Technomancer.essentials.api.BlockUtil;
4+
import com.Da_Technomancer.essentials.api.ConfigUtil;
5+
import com.Da_Technomancer.essentials.api.packets.ConfigureWrenchOnServer;
6+
import com.Da_Technomancer.essentials.api.packets.EssentialsPackets;
7+
import com.Da_Technomancer.essentials.api.redstone.IWireConnect;
48
import com.Da_Technomancer.essentials.blocks.WitherCannon;
5-
import com.Da_Technomancer.essentials.blocks.redstone.AbstractTile;
9+
import com.Da_Technomancer.essentials.blocks.redstone.CircuitTileEntity;
610
import com.Da_Technomancer.essentials.gui.*;
711
import com.Da_Technomancer.essentials.gui.container.*;
812
import com.Da_Technomancer.essentials.items.CircuitWrench;
913
import com.Da_Technomancer.essentials.items.ESItems;
10-
import com.Da_Technomancer.essentials.packets.ConfigureWrenchOnServer;
11-
import com.Da_Technomancer.essentials.packets.EssentialsPackets;
1214
import com.Da_Technomancer.essentials.render.CannonSkullRenderer;
13-
import com.Da_Technomancer.essentials.tileentities.redstone.CircuitTileEntity;
1415
import com.mojang.blaze3d.vertex.PoseStack;
1516
import com.mojang.math.Matrix4f;
1617
import net.minecraft.client.Minecraft;
@@ -21,7 +22,7 @@
2122
import net.minecraft.client.renderer.MultiBufferSource;
2223
import net.minecraft.client.renderer.entity.EntityRenderers;
2324
import net.minecraft.core.BlockPos;
24-
import net.minecraft.network.chat.TranslatableComponent;
25+
import net.minecraft.network.chat.Component;
2526
import net.minecraft.world.inventory.AbstractContainerMenu;
2627
import net.minecraft.world.inventory.MenuType;
2728
import net.minecraft.world.level.block.Block;
@@ -34,10 +35,11 @@
3435
import net.minecraftforge.client.event.ModelRegistryEvent;
3536
import net.minecraftforge.client.event.RenderLevelLastEvent;
3637
import net.minecraftforge.client.event.TextureStitchEvent;
37-
import net.minecraftforge.event.RegistryEvent;
3838
import net.minecraftforge.eventbus.api.SubscribeEvent;
3939
import net.minecraftforge.fml.common.Mod;
4040
import net.minecraftforge.network.IContainerFactory;
41+
import net.minecraftforge.registries.ForgeRegistries;
42+
import net.minecraftforge.registries.RegisterEvent;
4143

4244
import java.util.ArrayList;
4345

@@ -48,28 +50,30 @@ public static class ESModEventsClient{
4850

4951
@SubscribeEvent
5052
@SuppressWarnings("unused")
51-
public static void registerContainers(RegistryEvent.Register<MenuType<?>> e){
52-
registerCon(ItemShifterContainer::new, ItemShifterScreen::new, "item_shifter", e);
53-
registerCon(FluidShifterContainer::new, FluidShifterScreen::new, "fluid_shifter", e);
54-
registerCon(SlottedChestContainer::new, SlottedChestScreen::new, "slotted_chest", e);
55-
registerCon(CircuitWrenchContainer::new, CircuitWrenchScreen::new, "circuit_wrench", e);
56-
registerCon(ConstantCircuitContainer::new, ConstantCircuitScreen::new, "cons_circuit", e);
57-
registerCon(TimerCircuitContainer::new, TimerCircuitScreen::new, "timer_circuit", e);
58-
registerCon(AutoCrafterContainer::new, AutoCrafterScreen::new, "auto_crafter", e);
59-
registerCon(DelayCircuitContainer::new, DelayCircuitScreen::new, "delay_circuit", e);
60-
registerCon(PulseCircuitContainer::new, PulseCircuitScreen::new, "pulse_circuit", e);
53+
public static void registerContainers(RegisterEvent e){
54+
e.register(ForgeRegistries.Keys.CONTAINER_TYPES, helper -> {
55+
registerCon(ItemShifterContainer::new, ItemShifterScreen::new, "item_shifter", helper);
56+
registerCon(FluidShifterContainer::new, FluidShifterScreen::new, "fluid_shifter", helper);
57+
registerCon(SlottedChestContainer::new, SlottedChestScreen::new, "slotted_chest", helper);
58+
registerCon(CircuitWrenchContainer::new, CircuitWrenchScreen::new, "circuit_wrench", helper);
59+
registerCon(ConstantCircuitContainer::new, ConstantCircuitScreen::new, "cons_circuit", helper);
60+
registerCon(TimerCircuitContainer::new, TimerCircuitScreen::new, "timer_circuit", helper);
61+
registerCon(AutoCrafterContainer::new, AutoCrafterScreen::new, "auto_crafter", helper);
62+
registerCon(DelayCircuitContainer::new, DelayCircuitScreen::new, "delay_circuit", helper);
63+
registerCon(PulseCircuitContainer::new, PulseCircuitScreen::new, "pulse_circuit", helper);
64+
});
6165
}
6266

6367
/**
6468
* Creates and registers both a container type and a screen factory. Not usable on the physical server due to screen factory.
6569
* @param cons Container factory
6670
* @param screenFactory The screen factory to be linked to the type
6771
* @param id The ID to use
68-
* @param reg Registery event
72+
* @param helper Registry helper
6973
* @param <T> Container subclass
7074
*/
71-
private static <T extends AbstractContainerMenu> void registerCon(IContainerFactory<T> cons, MenuScreens.ScreenConstructor<T, AbstractContainerScreen<T>> screenFactory, String id, RegistryEvent.Register<MenuType<?>> reg){
72-
MenuType<T> contType = ESEventHandlerCommon.ESModEventsCommon.registerConType(cons, id, reg);
75+
private static <T extends AbstractContainerMenu> void registerCon(IContainerFactory<T> cons, MenuScreens.ScreenConstructor<T, AbstractContainerScreen<T>> screenFactory, String id, RegisterEvent.RegisterHelper<MenuType<?>> helper){
76+
MenuType<T> contType = ESEventHandlerCommon.ESModEventsCommon.registerConType(cons, id, helper);
7377
MenuScreens.register(contType, screenFactory);
7478
}
7579

@@ -104,7 +108,7 @@ public static void renderRedsOutput(RenderLevelLastEvent e){
104108
float output = ((CircuitTileEntity) te).getOutput();
105109
float[] relPos = {te.getBlockPos().getX() + 0.5F, te.getBlockPos().getY() + 0.5F, te.getBlockPos().getZ() + 0.5F};
106110
if(RANGE * RANGE > Minecraft.getInstance().getEntityRenderDispatcher().distanceToSqr(relPos[0], relPos[1], relPos[2])){
107-
renderNameplate(e.getPoseStack(), buffer, relPos, ESConfig.formatFloat(output, null));
111+
renderNameplate(e.getPoseStack(), buffer, relPos, ConfigUtil.formatFloat(output, null));
108112
}
109113
}
110114
}
@@ -134,13 +138,13 @@ public static void pickBlockCircuitWrench(InputEvent.ClickInputEvent e){
134138
if(hit.getType() == HitResult.Type.BLOCK){
135139
BlockPos pos = ((BlockHitResult) hit).getBlockPos();
136140
Block block = Minecraft.getInstance().level.getBlockState(pos).getBlock();
137-
if(block instanceof AbstractTile){
141+
if(block instanceof IWireConnect){
138142
//Because we're on the client side, we need to send a packet to the server updating the wrench
139143

140144
int index = -1;
141-
ArrayList<AbstractTile> modes = CircuitWrench.MODES;
145+
ArrayList<IWireConnect> modes = CircuitWrench.MODES;
142146
for(int i = 0; i < modes.size(); i++){
143-
AbstractTile tile = modes.get(i);
147+
IWireConnect tile = modes.get(i);
144148
if(tile == block){
145149
index = i;
146150
break;
@@ -149,12 +153,12 @@ public static void pickBlockCircuitWrench(InputEvent.ClickInputEvent e){
149153
if(index < 0){
150154
//Didn't find this circuit
151155
//Log an error and abort
152-
Essentials.logger.warn("Attempted to select unregistered circuit: " + block.getRegistryName());
156+
Essentials.logger.warn("Attempted to select unregistered circuit: " + ForgeRegistries.BLOCKS.getKey(block));
153157
return;
154158
}
155159
e.setCanceled(true);
156160
EssentialsPackets.channel.sendToServer(new ConfigureWrenchOnServer(index));
157-
Minecraft.getInstance().player.sendMessage(new TranslatableComponent("tt.essentials.circuit_wrench_setting").setStyle(CircuitWrenchScreen.CIRCUIT_WRENCH_STYLE).append(new TranslatableComponent(CircuitWrench.MODES.get(index).getDescriptionId())), Minecraft.getInstance().player.getUUID());
161+
Minecraft.getInstance().player.displayClientMessage(Component.translatable("tt.essentials.circuit_wrench_setting").setStyle(CircuitWrenchScreen.CIRCUIT_WRENCH_STYLE).append(Component.translatable(CircuitWrench.MODES.get(index).wireAsBlock().getDescriptionId())), true);
158162
}
159163
}
160164
}

0 commit comments

Comments
 (0)