Files
Postea/src/main/java/com/colen/postea/Postea.java
T

137 lines
5.8 KiB
Java
Raw Normal View History

2023-10-21 23:35:00 +01:00
package com.colen.postea;
2023-10-21 23:10:28 +01:00
2023-10-30 01:28:47 +00:00
import com.colen.postea.API.BlockReplacementManager;
2023-10-31 16:10:35 +00:00
import com.colen.postea.API.ItemStackReplacementManager;
2023-10-28 20:00:24 +01:00
import com.colen.postea.API.TileEntityReplacementManager;
2023-10-31 00:27:30 +00:00
import com.colen.postea.Utility.BlockConversionInfo;
import com.colen.postea.Utility.BlockInfo;
2023-10-21 23:10:28 +01:00
import cpw.mods.fml.common.Mod;
2023-10-24 01:44:51 +01:00
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
2023-10-31 00:27:30 +00:00
import net.minecraft.block.Block;
2023-10-28 20:00:24 +01:00
import net.minecraft.init.Blocks;
2023-10-31 16:10:35 +00:00
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.nbt.NBTTagCompound;
2023-10-29 23:53:12 +00:00
import net.minecraft.nbt.NBTTagList;
import java.util.function.Function;
2023-10-21 23:10:28 +01:00
2023-10-31 00:27:30 +00:00
import static com.colen.postea.Utility.PosteaUtilities.cleanseNBT;
2023-10-21 23:10:28 +01:00
@Mod(modid = Tags.MODID, version = Tags.VERSION, name = Tags.MODNAME, acceptedMinecraftVersions = "[1.7.10]")
@SuppressWarnings("unused")
public class Postea {
@Mod.EventHandler
public void preInit(FMLPreInitializationEvent event) {
2023-10-31 16:10:35 +00:00
// This is an example of replacing GT ore blocks depending on the dimension. Because BlockInfo has no TileEntity
// transformer set, it will delete the underlying tile entity fully. This will essentially convert a TE block to a non-TE block.
// You can use the data in the tile to determine this conversion from the "tag" variable.
2023-10-30 20:02:08 +00:00
TileEntityReplacementManager.tileEntityTransformer("GT_TileEntity_Ores", (tag, world) -> {
if (world.provider.dimensionId == -1) {
2023-10-31 00:27:30 +00:00
return new BlockInfo(Blocks.wool, 1);
2023-10-30 20:02:08 +00:00
}
if (world.provider.dimensionId == 1) {
2023-10-31 00:27:30 +00:00
return new BlockInfo(Blocks.wool, 2);
2023-10-29 01:37:24 +00:00
}
2023-10-28 20:00:24 +01:00
2023-10-31 00:27:30 +00:00
return new BlockInfo(Blocks.wool, 3);
2023-10-29 01:37:24 +00:00
});
2023-10-29 21:18:26 +00:00
2023-10-31 16:10:35 +00:00
// This is an example of how to replace another tile entity and it's block. Here we are replacing furnaces with chests.
// It will then also replace the furnace block with a chest. Otherwise the Tile would not match the block.
TileEntityReplacementManager.tileEntityTransformer("Furnace", (tag, world) -> {
2023-10-29 23:53:12 +00:00
Function<NBTTagCompound, NBTTagCompound> chestTransformer = (oldTag) -> {
NBTTagCompound newTag = cleanseNBT("Chest", oldTag);
NBTTagList tagList = new NBTTagList();
NBTTagCompound stoneAtSlot13 = new NBTTagCompound();
stoneAtSlot13.setByte("Count", (byte) 1);
stoneAtSlot13.setByte("Slot", (byte) 13);
stoneAtSlot13.setShort("Damage", (short) 0);
stoneAtSlot13.setShort("id", (short) 1);
tagList.appendTag(stoneAtSlot13);
newTag.setTag("Items", tagList);
return newTag;
};
2023-10-31 16:10:35 +00:00
return new BlockInfo(Blocks.chest, 0, chestTransformer);
});
2023-10-29 23:53:12 +00:00
2023-10-31 16:10:35 +00:00
// This is an example of how to change the data of a specific tile entity. You provide the Tiles ID e.g. Chest
// and then provide a conversion function. In this instance we are changing the contents of a chest.
// This will replace the contents fully with stone and jungle planks at specific slots.
2023-10-30 20:02:08 +00:00
TileEntityReplacementManager.tileEntityTransformer("Chest", (tag, world) -> {
2023-10-29 23:53:12 +00:00
Function<NBTTagCompound, NBTTagCompound> chestTransformer = (oldTag) -> {
NBTTagCompound newTag = cleanseNBT("Chest", oldTag);
NBTTagList tagList = new NBTTagList();
NBTTagCompound stoneAtSlot12 = new NBTTagCompound();
stoneAtSlot12.setByte("Count", (byte) 2);
stoneAtSlot12.setByte("Slot", (byte) 12);
stoneAtSlot12.setShort("Damage", (short) 0);
2023-10-31 16:10:35 +00:00
stoneAtSlot12.setShort("id", (short) Block.getIdFromBlock(Blocks.stone));
2023-10-29 23:53:12 +00:00
NBTTagCompound stoneAtSlot14 = new NBTTagCompound();
stoneAtSlot14.setByte("Count", (byte) 4);
stoneAtSlot14.setByte("Slot", (byte) 14);
stoneAtSlot14.setShort("Damage", (short) 3);
2023-10-31 16:10:35 +00:00
stoneAtSlot14.setShort("id", (short) Block.getIdFromBlock(Blocks.planks));
2023-10-29 23:53:12 +00:00
tagList.appendTag(stoneAtSlot12);
tagList.appendTag(stoneAtSlot14);
newTag.setTag("Items", tagList);
return newTag;
};
2023-10-31 00:27:30 +00:00
return new BlockInfo(Blocks.chest, 0, chestTransformer);
2023-10-29 21:18:26 +00:00
});
2023-10-29 23:53:12 +00:00
2023-10-30 01:28:47 +00:00
2023-10-31 16:10:35 +00:00
// Example of how to replace a non-TE block with another non-TE block, this replaces grass with wool.
// It converts every grass block with an even x coordinate to orange wool.
2023-10-31 00:27:30 +00:00
Function<BlockConversionInfo, BlockConversionInfo> blockTransformer = (blockConversionInfoOld) -> {
BlockConversionInfo blockConversionInfoNew = new BlockConversionInfo();
2023-10-29 23:53:12 +00:00
2023-10-31 16:10:35 +00:00
if ((blockConversionInfoOld.x % 2 == 0)) {
2023-10-31 00:27:30 +00:00
blockConversionInfoNew.blockID = Block.getIdFromBlock(Blocks.wool);
blockConversionInfoNew.metadata = 1;
2023-10-31 01:09:19 +00:00
} else {
blockConversionInfoNew.blockID = blockConversionInfoOld.blockID;
blockConversionInfoNew.metadata = blockConversionInfoOld.metadata;
2023-10-31 00:27:30 +00:00
}
return blockConversionInfoNew;
};
2023-10-29 23:53:12 +00:00
2023-10-31 00:27:30 +00:00
BlockReplacementManager.addBlockReplacement("minecraft:grass", blockTransformer);
2023-10-29 23:53:12 +00:00
2023-10-28 20:00:24 +01:00
2023-10-31 16:10:35 +00:00
// Example of how to replace an item, this replaces iron ingots with gold ingots.
// You can manipulate stack size but it isn't recommended.
// You can also use the tag associated with this ItemStack to determine the replacement.
Function<NBTTagCompound, NBTTagCompound> itemTransformer = (tag) -> {
tag.setShort("id", (short) Item.getIdFromItem(Items.gold_ingot));
return tag;
};
ItemStackReplacementManager.addItemReplacement("minecraft:iron_ingot", itemTransformer);
2023-10-24 01:44:51 +01:00
}
2023-10-21 23:10:28 +01:00
}