Skip to content

Commit 08f3f9a

Browse files
authored
Merge branch 'master' into GTHH-GregTech-2.8.10
2 parents 12af6c8 + 8fee80a commit 08f3f9a

File tree

86 files changed

+2363
-386
lines changed

Some content is hidden

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

86 files changed

+2363
-386
lines changed

src/main/java/gregtech/api/capability/GregtechDataCodes.java

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
11
package gregtech.api.capability;
22

3+
import it.unimi.dsi.fastutil.ints.Int2ObjectArrayMap;
4+
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
5+
import org.apache.commons.lang3.ArrayUtils;
6+
7+
import java.lang.reflect.Field;
8+
import java.lang.reflect.Modifier;
9+
310
public class GregtechDataCodes {
411

12+
public static final int UPDATE_PRIVATE = assignId();
13+
public static final int LOCK_FILL = assignId();
514
private static int nextId = 0;
615

716
public static int assignId() {
@@ -180,4 +189,36 @@ public static int assignId() {
180189
// ME Parts
181190
public static final int UPDATE_AUTO_PULL = assignId();
182191
public static final int UPDATE_ONLINE_STATUS = assignId();
192+
193+
// Everything below MUST be last in the class!
194+
public static final Int2ObjectMap<String> NAMES = new Int2ObjectArrayMap<>();
195+
196+
static {
197+
registerFields(GregtechDataCodes.class);
198+
}
199+
200+
public static String getNameFor(int id) {
201+
return NAMES.getOrDefault(id, "Unknown_DataCode:" + id);
202+
}
203+
204+
/**
205+
* Registers all fields from the passed in class to the name registry.
206+
* Optionally, you can pass in a list of valid ids to check against so that errant ids are not added
207+
*
208+
* @param clazz Class to iterate fields
209+
* @param validIds optional array of valid ids to check against class fields
210+
*/
211+
public static void registerFields(Class<?> clazz, int... validIds) {
212+
try {
213+
for (Field field : clazz.getDeclaredFields()) {
214+
if (field.getType() != Integer.TYPE) continue;
215+
if (!Modifier.isStatic(field.getModifiers())) continue;
216+
if (!Modifier.isFinal(field.getModifiers())) continue;
217+
int id = field.getInt(null);
218+
if (!ArrayUtils.isEmpty(validIds) && !ArrayUtils.contains(validIds, id))
219+
continue;
220+
NAMES.put(id, field.getName() + ":" + id);
221+
}
222+
} catch (IllegalAccessException ignored) {}
223+
}
183224
}

src/main/java/gregtech/api/cover/CoverSaveHandler.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package gregtech.api.cover;
22

3+
import gregtech.api.metatileentity.interfaces.ISyncedTileEntity;
34
import gregtech.api.util.GTLog;
45

56
import net.minecraft.nbt.NBTTagCompound;
@@ -66,6 +67,7 @@ public static void receiveInitialSyncData(@NotNull PacketBuffer buf, @NotNull Co
6667
} else {
6768
Cover cover = definition.createCover(coverHolder, facing);
6869
cover.readInitialSyncData(buf);
70+
ISyncedTileEntity.checkInitialData(buf, cover);
6971
coverHolder.addCover(facing, cover);
7072
}
7173
}
@@ -107,6 +109,7 @@ public static void readCoverPlacement(@NotNull PacketBuffer buf, @NotNull CoverH
107109
coverHolder.addCover(placementSide, cover);
108110

109111
cover.readInitialSyncData(buf);
112+
ISyncedTileEntity.checkInitialData(buf, cover);
110113
}
111114
coverHolder.scheduleRenderUpdate();
112115
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
package gregtech.api.items;
2+
3+
import net.minecraft.block.BlockCauldron;
4+
import net.minecraft.block.state.IBlockState;
5+
import net.minecraft.entity.player.EntityPlayer;
6+
import net.minecraft.item.ItemStack;
7+
import net.minecraft.nbt.NBTTagCompound;
8+
import net.minecraft.util.EnumActionResult;
9+
import net.minecraft.util.EnumFacing;
10+
import net.minecraft.util.EnumHand;
11+
import net.minecraft.util.math.BlockPos;
12+
import net.minecraft.world.World;
13+
import net.minecraftforge.common.util.Constants;
14+
15+
import org.jetbrains.annotations.NotNull;
16+
17+
public interface IDyeableItem {
18+
19+
String COLOR_KEY = "gt_color";
20+
21+
default boolean hasColor(ItemStack stack) {
22+
NBTTagCompound nbttagcompound = stack.getTagCompound();
23+
return nbttagcompound != null && nbttagcompound.hasKey(COLOR_KEY, Constants.NBT.TAG_INT);
24+
}
25+
26+
default int getColor(ItemStack stack) {
27+
NBTTagCompound nbttagcompound = stack.getTagCompound();
28+
if (nbttagcompound != null && nbttagcompound.hasKey(COLOR_KEY, Constants.NBT.TAG_INT)) {
29+
return nbttagcompound.getInteger(COLOR_KEY);
30+
}
31+
return getDefaultColor(stack);
32+
}
33+
34+
default int getDefaultColor(ItemStack stack) {
35+
return 0xFFFFFF;
36+
}
37+
38+
default void removeColor(ItemStack stack) {
39+
NBTTagCompound nbttagcompound = stack.getTagCompound();
40+
if (nbttagcompound != null && nbttagcompound.hasKey(COLOR_KEY)) {
41+
nbttagcompound.removeTag(COLOR_KEY);
42+
}
43+
}
44+
45+
default void setColor(ItemStack stack, int color) {
46+
NBTTagCompound nbttagcompound = stack.getTagCompound();
47+
if (nbttagcompound == null) {
48+
nbttagcompound = new NBTTagCompound();
49+
stack.setTagCompound(nbttagcompound);
50+
}
51+
nbttagcompound.setInteger(COLOR_KEY, color);
52+
}
53+
54+
default @NotNull EnumActionResult onItemUseFirst(@NotNull EntityPlayer player, @NotNull World world,
55+
@NotNull BlockPos pos, @NotNull EnumFacing side, float hitX,
56+
float hitY, float hitZ, @NotNull EnumHand hand) {
57+
ItemStack stack = player.getHeldItem(hand);
58+
if (this.hasColor(stack)) {
59+
IBlockState iblockstate = world.getBlockState(pos);
60+
if (iblockstate.getBlock() instanceof BlockCauldron cauldron) {
61+
int water = iblockstate.getValue(BlockCauldron.LEVEL);
62+
if (water > 0) {
63+
this.removeColor(stack);
64+
cauldron.setWaterLevel(world, pos, iblockstate, water - 1);
65+
return EnumActionResult.SUCCESS;
66+
}
67+
}
68+
}
69+
return EnumActionResult.PASS;
70+
}
71+
72+
/**
73+
* Controls whether the dyeing recipe simply removes the dyeable item from the crafting grid,
74+
* or calls {@link net.minecraftforge.common.ForgeHooks#getContainerItem(ItemStack)} on it.
75+
*/
76+
default boolean shouldGetContainerItem() {
77+
return true;
78+
}
79+
}

0 commit comments

Comments
 (0)