Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
48b52f9
just because i can, doesn't mean i should
ghzdude Dec 11, 2025
7404eee
also start tile entity
ghzdude Dec 11, 2025
5edf988
move map access to GTUtility
ghzdude Dec 11, 2025
b9bfab6
retrieve mte from resloc
ghzdude Dec 12, 2025
c999525
spotless
ghzdude Dec 12, 2025
d3d7a55
initial base TE
ghzdude Dec 12, 2025
09f4b4e
make it a supplier
ghzdude Dec 12, 2025
f2e5383
off by one only on x???
ghzdude Dec 12, 2025
7887457
The Big One™
ghzdude Dec 12, 2025
73facc2
The Big One™ pt 2
ghzdude Dec 12, 2025
0621cef
fix block info a bit plus other stuff and notes
ghzdude Dec 13, 2025
a122cf0
everywhere set MTE was called needs to duplicate the MTE instance
ghzdude Dec 13, 2025
fae3c2d
put TE in world directly
ghzdude Dec 14, 2025
9759ec2
almost everything works
ghzdude Dec 14, 2025
71650ae
fix render update
ghzdude Dec 14, 2025
16bb761
note
ghzdude Dec 16, 2025
7c06dfd
i think it's fully working now
ghzdude Dec 16, 2025
d3a6562
misc things
ghzdude Dec 16, 2025
4bae1c9
delete placing TE threadlocal and related methods
ghzdude Dec 20, 2025
0c55744
documentation
ghzdude Dec 20, 2025
d4d6cc7
delete commented code
ghzdude Dec 20, 2025
b862538
move `copy()` to IGregTechTileEntity
ghzdude Dec 20, 2025
b36d4b4
simplify holder in`BlockMachine#onBlockPlacedBy`
ghzdude Dec 20, 2025
afd2f54
more cleanup
ghzdude Dec 20, 2025
fad79a5
fix tests
ghzdude Dec 20, 2025
c3bc098
read mte tag to mte
ghzdude Dec 20, 2025
d4ee338
simplify EventHandlers
ghzdude Dec 20, 2025
07e8c29
fix hull
ghzdude Dec 20, 2025
8eae4e8
more cleanup
ghzdude Dec 20, 2025
17691d5
replace instanceof cast with overridable method
ghzdude Dec 20, 2025
0ec33f0
move logic into hook class
ghzdude Dec 21, 2025
954ed7a
update docs
ghzdude Dec 21, 2025
32da5ec
address todo and simplify return
ghzdude Dec 22, 2025
e3a1ebc
simplify and remove optional chaining
ghzdude Dec 23, 2025
21c12b1
delete unused method
ghzdude Dec 23, 2025
7740330
clean out mte holder
ghzdude Dec 23, 2025
47bb2e9
don't write empty name strings to nbt
ghzdude Dec 23, 2025
b4eaa1d
remove old comments
ghzdude Dec 24, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 27 additions & 19 deletions src/main/java/gregtech/api/block/machines/BlockMachine.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import gregtech.api.items.toolitem.ToolClasses;
import gregtech.api.items.toolitem.ToolHelper;
import gregtech.api.metatileentity.MetaTileEntity;
import gregtech.api.metatileentity.MetaTileEntityHolder;
import gregtech.api.metatileentity.interfaces.IGregTechTileEntity;
import gregtech.api.metatileentity.multiblock.MultiblockControllerBase;
import gregtech.api.metatileentity.registry.MTERegistry;
Expand Down Expand Up @@ -266,39 +265,47 @@ public boolean recolorBlock(@NotNull World world, @NotNull BlockPos pos, @NotNul
@Override
public void onBlockPlacedBy(World worldIn, @NotNull BlockPos pos, @NotNull IBlockState state,
@NotNull EntityLivingBase placer, ItemStack stack) {
IGregTechTileEntity holder = (IGregTechTileEntity) worldIn.getTileEntity(pos);
MTERegistry registry = GregTechAPI.mteManager.getRegistry(
Objects.requireNonNull(stack.getItem().getRegistryName()).getNamespace());
MetaTileEntity sampleMetaTileEntity = GTUtility.getMetaTileEntity(stack);

MetaTileEntity sampleMetaTileEntity = registry.getObjectById(stack.getItemDamage());
if (holder == null || sampleMetaTileEntity == null)
if (sampleMetaTileEntity == null)
return;

// TODO Fix this
if (stack.hasDisplayName() && holder instanceof MetaTileEntityHolder) {
((MetaTileEntityHolder) holder).setCustomName(stack.getDisplayName());
}
MetaTileEntity metaTileEntity = sampleMetaTileEntity.copy();

var stackTag = stack.getTagCompound();
NBTTagCompound mteTag = null;
if (stackTag != null && !stackTag.isEmpty()) {
if (stackTag.hasKey(GregtechDataCodes.BLOCK_ENTITY_TAG)) {
var blockTag = stackTag.getCompoundTag(GregtechDataCodes.BLOCK_ENTITY_TAG);
String customName = blockTag.getString(GregtechDataCodes.CUSTOM_NAME);
if (!customName.isEmpty())
((MetaTileEntityHolder) holder).setCustomName(customName);
metaTileEntity.setCustomName(customName);

mteTag = blockTag.getCompoundTag(GregtechDataCodes.TAG_KEY_MTE);
List<String> removed = new ArrayList<>();
for (var key : mteTag.getKeySet()) {
var trait = sampleMetaTileEntity.getMTETrait(key);
var trait = metaTileEntity.getMTETrait(key);
if (trait == null) continue;

removed.add(key);
}
removed.forEach(mteTag::removeTag);
}
}
MetaTileEntity metaTileEntity = holder.setMetaTileEntity(sampleMetaTileEntity, mteTag);

if (mteTag != null) {
metaTileEntity.readMTETag(mteTag);
}

if (!GTUtility.hasTileEntity(worldIn, pos)) {
worldIn.setTileEntity(pos, metaTileEntity);
}

// TODO Fix this
if (stack.hasDisplayName()) {
metaTileEntity.setCustomName(stack.getDisplayName());
}

if (mteTag == null) {
if (stackTag != null && !stackTag.isEmpty())
metaTileEntity.initFromItemStackData(stackTag);
Expand Down Expand Up @@ -372,11 +379,9 @@ public void getDrops(@NotNull NonNullList<ItemStack> drops, @NotNull IBlockAcces
if (!tagCompound.isEmpty())
itemStack.setTagCompound(tagCompound);
// TODO Clean this up
if (metaTileEntity.getHolder() instanceof MetaTileEntityHolder) {
MetaTileEntityHolder holder = (MetaTileEntityHolder) metaTileEntity.getHolder();
if (holder.hasCustomName()) {
itemStack.setStackDisplayName(holder.getName());
}
// clean up how exactly?
if (metaTileEntity.hasCustomName()) {
itemStack.setStackDisplayName(metaTileEntity.getName());
}
drops.add(itemStack);
metaTileEntity.getDrops(drops, harvesters.get());
Expand Down Expand Up @@ -475,7 +480,10 @@ public void harvestBlock(@NotNull World worldIn, @NotNull EntityPlayer player, @
@Nullable
@Override
public TileEntity createNewTileEntity(@Nullable World worldIn, int meta) {
return new MetaTileEntityHolder();
// i wonder if it would be a good idea to give a "proto" TE
// though that's really just mte holder but in a different way
// actually just return null, TE is handled elsewhere
return null;
}

@NotNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,8 @@ public void setMinEnergyTier(int energyTier) {

/**
* writes all needed values to NBT
* This MUST be called and returned in the MetaTileEntity's {@link MetaTileEntity#writeToNBT(NBTTagCompound)} method
* This MUST be called and returned in the MetaTileEntity's {@link MetaTileEntity#writeMTETag(NBTTagCompound)}
* method
*/
public NBTTagCompound writeToNBT(@NotNull NBTTagCompound data) {
data.setBoolean("isActive", this.isActive);
Expand All @@ -191,7 +192,7 @@ public NBTTagCompound writeToNBT(@NotNull NBTTagCompound data) {

/**
* reads all needed values from NBT
* This MUST be called and returned in the MetaTileEntity's {@link MetaTileEntity#readFromNBT(NBTTagCompound)}
* This MUST be called and returned in the MetaTileEntity's {@link MetaTileEntity#readMTETag(NBTTagCompound)}
* method
*/
public void readFromNBT(@NotNull NBTTagCompound data) {
Expand All @@ -205,7 +206,7 @@ public void readFromNBT(@NotNull NBTTagCompound data) {
/**
* writes all needed values to InitialSyncData
* This MUST be called and returned in the MetaTileEntity's
* {@link MetaTileEntity#writeInitialSyncData(PacketBuffer)} method
* {@link MetaTileEntity#writeInitialSyncDataMTE(PacketBuffer)} method
*/
public void writeInitialSyncData(@NotNull PacketBuffer buf) {
buf.writeBoolean(this.isActive);
Expand All @@ -218,7 +219,7 @@ public void writeInitialSyncData(@NotNull PacketBuffer buf) {
/**
* reads all needed values from InitialSyncData
* This MUST be called and returned in the MetaTileEntity's
* {@link MetaTileEntity#receiveInitialSyncData(PacketBuffer)} method
* {@link MetaTileEntity#receiveInitialSyncDataMTE(PacketBuffer)} method
*/
public void receiveInitialSyncData(@NotNull PacketBuffer buf) {
setActive(buf.readBoolean());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,8 @@ public boolean isInventoryFull() {

/**
* writes all needed values to NBT
* This MUST be called and returned in the MetaTileEntity's {@link MetaTileEntity#writeToNBT(NBTTagCompound)} method
* This MUST be called and returned in the MetaTileEntity's {@link MetaTileEntity#writeMTETag(NBTTagCompound)}
* method
*/
public NBTTagCompound writeToNBT(@NotNull NBTTagCompound data) {
data.setBoolean("isActive", this.isActive);
Expand All @@ -266,7 +267,7 @@ public NBTTagCompound writeToNBT(@NotNull NBTTagCompound data) {

/**
* reads all needed values from NBT
* This MUST be called and returned in the MetaTileEntity's {@link MetaTileEntity#readFromNBT(NBTTagCompound)}
* This MUST be called and returned in the MetaTileEntity's {@link MetaTileEntity#readMTETag(NBTTagCompound)}
* method
*/
public void readFromNBT(@NotNull NBTTagCompound data) {
Expand All @@ -281,7 +282,7 @@ public void readFromNBT(@NotNull NBTTagCompound data) {
/**
* writes all needed values to InitialSyncData
* This MUST be called and returned in the MetaTileEntity's
* {@link MetaTileEntity#writeInitialSyncData(PacketBuffer)} method
* {@link MetaTileEntity#writeInitialSyncDataMTE(PacketBuffer)} method
*/
public void writeInitialSyncData(@NotNull PacketBuffer buf) {
buf.writeBoolean(this.isActive);
Expand All @@ -294,7 +295,7 @@ public void writeInitialSyncData(@NotNull PacketBuffer buf) {
/**
* reads all needed values from InitialSyncData
* This MUST be called and returned in the MetaTileEntity's
* {@link MetaTileEntity#receiveInitialSyncData(PacketBuffer)} method
* {@link MetaTileEntity#receiveInitialSyncDataMTE(PacketBuffer)} method
*/
public void receiveInitialSyncData(@NotNull PacketBuffer buf) {
setActive(buf.readBoolean());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,8 @@ protected ICubeRenderer getPipeTexture() {

/**
* writes all needed values to NBT
* This MUST be called and returned in the MetaTileEntity's {@link MetaTileEntity#writeToNBT(NBTTagCompound)} method
* This MUST be called and returned in the MetaTileEntity's {@link MetaTileEntity#writeMTETag(NBTTagCompound)}
* method
*/
public NBTTagCompound writeToNBT(@NotNull NBTTagCompound data) {
data.setTag("xPos", new NBTTagInt(x.get()));
Expand All @@ -525,7 +526,7 @@ public NBTTagCompound writeToNBT(@NotNull NBTTagCompound data) {

/**
* reads all needed values from NBT
* This MUST be called and returned in the MetaTileEntity's {@link MetaTileEntity#readFromNBT(NBTTagCompound)}
* This MUST be called and returned in the MetaTileEntity's {@link MetaTileEntity#readMTETag(NBTTagCompound)}
* method
*/
public void readFromNBT(@NotNull NBTTagCompound data) {
Expand All @@ -550,7 +551,7 @@ public void readFromNBT(@NotNull NBTTagCompound data) {
/**
* writes all needed values to InitialSyncData
* This MUST be called and returned in the MetaTileEntity's
* {@link MetaTileEntity#writeInitialSyncData(PacketBuffer)} method
* {@link MetaTileEntity#writeInitialSyncDataMTE(PacketBuffer)} method
*/
public void writeInitialSyncData(@NotNull PacketBuffer buf) {
buf.writeInt(pipeLength);
Expand All @@ -562,7 +563,7 @@ public void writeInitialSyncData(@NotNull PacketBuffer buf) {
/**
* reads all needed values from InitialSyncData
* This MUST be called and returned in the MetaTileEntity's
* {@link MetaTileEntity#receiveInitialSyncData(PacketBuffer)} method
* {@link MetaTileEntity#receiveInitialSyncDataMTE(PacketBuffer)} method
*/
public void receiveInitialSyncData(@NotNull PacketBuffer buf) {
this.pipeLength = buf.readInt();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import gregtech.api.items.IDyeableItem;
import gregtech.api.items.gui.ItemUIFactory;
import gregtech.api.items.toolitem.behavior.IToolBehavior;
import gregtech.api.metatileentity.MetaTileEntityHolder;
import gregtech.api.mui.GTGuiTextures;
import gregtech.api.mui.GTGuis;
import gregtech.api.unification.material.Material;
Expand Down Expand Up @@ -481,8 +480,7 @@ public void setSelectedTool(int slot, ItemStack stack) {
ItemStack stack = player.getHeldItem(hand);
ToolStackHandler handler = getHandler(stack);
if (handler.getSelectedStack().isEmpty() &&
world.getTileEntity(pos) instanceof MetaTileEntityHolder holder &&
holder.getMetaTileEntity() instanceof MetaTileEntityMaintenanceHatch maintenance) {
world.getTileEntity(pos) instanceof MetaTileEntityMaintenanceHatch maintenance) {
maintenance.fixMaintenanceProblemsWithToolbelt(player, this, stack);
return EnumActionResult.SUCCESS;
}
Expand Down
Loading
Loading