Skip to content

Commit

Permalink
new block API fixes, distill now uses new API
Browse files Browse the repository at this point in the history
- Fixed block rotation on item frames
- Fixed some rotation bugs with the new block API
- Fixed a crash with the new block API
- Updated the creative tab to have some of the features missing from TiM
  • Loading branch information
EternalBlueFlame committed Jul 17, 2024
1 parent 9fd5d2b commit da91cbc
Show file tree
Hide file tree
Showing 22 changed files with 93 additions and 30 deletions.
1 change: 1 addition & 0 deletions src/main/java/ebf/tim/render/CustomItemModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ public void renderItem(ItemRenderType type, ItemStack item, Object... data) {
case EQUIPPED:{break;}
case FIRST_PERSON_MAP:{break;}
case ENTITY:{
GL11.glRotatef(180,0,1,0);
GL11.glTranslatef(-0.5f,-0.4f,-0.5f);
break;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package train.client.core.handlers;

import net.minecraft.item.Item;
import train.common.blocks.TCBlocks;
import train.common.core.interfaces.ITCRecipe;
import train.common.core.managers.TierRecipe;
import train.common.library.BlockIDs;
Expand All @@ -23,7 +24,7 @@ public RecipeBookHandler() {
vanillaWorkTableRecipes[0] = BlockIDs.assemblyTableI.block.getUnlocalizedName();
vanillaWorkTableRecipes[1] = BlockIDs.assemblyTableII.block.getUnlocalizedName();
vanillaWorkTableRecipes[2] = BlockIDs.assemblyTableIII.block.getUnlocalizedName();
vanillaWorkTableRecipes[3] = BlockIDs.distilIdle.block.getUnlocalizedName();
vanillaWorkTableRecipes[3] = TCBlocks.distilIdle.getUnlocalizedName();
vanillaWorkTableRecipes[4] = BlockIDs.openFurnaceIdle.block.getUnlocalizedName();
vanillaWorkTableRecipes[5] = BlockIDs.trainWorkbench.block.getUnlocalizedName();
vanillaWorkTableRecipes[6] = ItemIDs.overalls.item.getUnlocalizedName();
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/train/client/gui/GuiRecipeBook.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import net.minecraft.util.StatCollector;
import org.lwjgl.opengl.GL11;
import train.client.core.handlers.RecipeBookHandler;
import train.common.blocks.TCBlocks;
import train.common.core.managers.TierRecipe;
import train.common.core.managers.TierRecipeManager;
import train.common.inventory.TrainCraftingManager;
Expand Down Expand Up @@ -290,8 +291,8 @@ public GuiRecipeBook(EntityPlayer par1EntityPlayer, ItemStack par2ItemStack) {

addPage("Making diesel:\nDiesel is made in a distillation tower using petroleum or oil sands found in the world.\nInsert petroleum in the top slot and fuel in the bottom slot, also try reed.\nIt will cook into liquid diesel and give you plastic with a random chance depending on the input.\nTo get diesel into canisters, you must first craft them using plastic. Then put an empty one in the top right slot.", "", "right", new ArrayList<StackToDraw>() {
{
add(new StackToDraw(new ItemStack(BlockIDs.distilIdle.block), 20, 16));
add(new StackToDraw(new ItemStack(BlockIDs.distilActive.block), 150, 40));
add(new StackToDraw(new ItemStack(TCBlocks.distilIdle), 20, 16));
add(new StackToDraw(new ItemStack(TCBlocks.distilActive), 150, 40));
add(new StackToDraw(new ItemStack(BlockIDs.oreTC.block, 1, 1), 150, 20));
add(new StackToDraw(new ItemStack(Items.coal), 150, 60));
add(new StackToDraw(new ItemStack(ItemIDs.diesel.item), 167, 40));
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/train/common/Traincraft.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import train.common.generation.WorldGenWorld;
import train.common.items.TCItems;
import train.common.library.Info;
import train.common.library.ItemIDs;
import train.common.library.TraincraftRegistry;
import train.common.recipes.AssemblyTableRecipes;

Expand Down Expand Up @@ -96,7 +97,7 @@ public class Traincraft {
public static File configDirectory;

/* Creative tab for Traincraft */
public static CreativeTabs tcTab, tcTrainTab;
public static CreativeTabTraincraft tcTab, tcTrainTab;

public ArmorMaterial armor = EnumHelper.addArmorMaterial("Armor", 5, new int[]{1, 2, 2, 1}, 25);
public ArmorMaterial armorCloth = EnumHelper.addArmorMaterial("TCcloth", 5, new int[]{1, 2, 2, 1}, 25);
Expand All @@ -122,9 +123,9 @@ public void preInit(FMLPreInitializationEvent event) {

/* Register Items, Blocks, ... */
tcLog.info("Initialize Blocks, Items, ...");
tcTab = new CreativeTabTraincraft(CreativeTabs.getNextID(), "Traincraft");
tcTab = new CreativeTabTraincraft("Traincraft", Info.modID, "trains/train_br80");
if (ConfigHandler.SPLIT_CREATIVE) {
tcTrainTab = new CreativeTabTraincraftTrains(CreativeTabs.getNextID(), "Traincraft Trains");
tcTrainTab = new CreativeTabTraincraft("Traincraft Trains", Info.modID,"trains/train_br01");
}
trainArmor = proxy.addArmor("armor");
trainCloth = proxy.addArmor("Paintable");
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/train/common/api/blocks/TileRenderFacing.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,9 @@ public void func_145828_a(CrashReportCategory r){
org.lwjgl.opengl.GL11.glTranslatef(0.5f,0.5f,0.5f);
switch (facing){
//north
case 0:{ org.lwjgl.opengl.GL11.glRotatef(180,0,1,0);break;}
case 0:{ org.lwjgl.opengl.GL11.glRotatef(90,0,1,0);break;}
//east
case 1:{org.lwjgl.opengl.GL11.glRotatef(90,0,1,0);break;}
case 1:{org.lwjgl.opengl.GL11.glRotatef(180,0,1,0);break;}
//south
case 2:{ org.lwjgl.opengl.GL11.glRotatef(270,0,1,0);break;}
//west
Expand All @@ -121,7 +121,7 @@ public void func_145828_a(CrashReportCategory r){

@SideOnly(Side.CLIENT)
public void renderModel(){
if(host.model!=null) {
if(host!=null && host.model!=null) {
host.model.render();
} else {
if(blockGLID ==null) {
Expand Down
25 changes: 20 additions & 5 deletions src/main/java/train/common/blocks/BlockDistil.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import ebf.tim.utility.CommonUtil;
import net.minecraft.block.Block;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.item.EntityItem;
Expand All @@ -14,10 +16,12 @@
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.IIcon;
import net.minecraft.util.MathHelper;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
import train.common.Traincraft;
import train.common.api.blocks.BlockDynamic;
import train.common.library.BlockIDs;
import train.common.library.GuiIDs;
import train.common.library.Info;
Expand All @@ -26,7 +30,7 @@

import java.util.Random;

public class BlockDistil extends BlockContainer {
public class BlockDistil extends BlockDynamic {

private final boolean isActive;
private static boolean keepDistilInventory = false;
Expand All @@ -40,7 +44,7 @@ public class BlockDistil extends BlockContainer {
private IIcon textureBack;

public BlockDistil(int j, boolean flag) {
super(Material.anvil);
super(Material.anvil,j);
isActive = flag;
distilRand = new Random();
//setRequiresSelfNotify();
Expand All @@ -54,7 +58,7 @@ public BlockDistil(int j, boolean flag) {

@Override
public Item getItemDropped(int i, Random random, int j) {
return Item.getItemFromBlock(BlockIDs.distilIdle.block);
return Item.getItemFromBlock(TCBlocks.distilIdle);
}

@Override
Expand Down Expand Up @@ -160,10 +164,10 @@ public static void updateDistilBlockState(boolean flag, World world, int i, int
TileEntity tileentity = world.getTileEntity(i, j, k);
keepDistilInventory = true;
if (flag) {
world.setBlock(i, j, k, BlockIDs.distilActive.block);
world.setBlock(i, j, k, TCBlocks.distilActive);
}
else {
world.setBlock(i, j, k, BlockIDs.distilIdle.block);
world.setBlock(i, j, k, TCBlocks.distilIdle);
}
keepDistilInventory = false;
world.setBlockMetadataWithNotify(i, j, k, l, 2);
Expand Down Expand Up @@ -224,10 +228,21 @@ public void onBlockPlacedBy(World world, int i, int j, int k, EntityLivingBase e
}
}

@Override
@SideOnly(Side.CLIENT)
public ResourceLocation getTexture(int x, int y, int z){
return new ResourceLocation(Info.modID,
((x==0&&y==0&&z==0)||CommonUtil.getBlockAt(Minecraft.getMinecraft().theWorld,x,y,z)==TCBlocks.distilActive)?
"textures/blocks/distil_on.png":"textures/blocks/distil_off.png");
}
@Override
public TileEntity createNewTileEntity(World world, int meta) {
return new TileEntityDistil();
}
@Override
public TileEntity createTileEntity(World world, int metadata) {
return new TileEntityDistil();
}

@Override
@SideOnly(Side.CLIENT)
Expand Down
8 changes: 6 additions & 2 deletions src/main/java/train/common/blocks/TCBlocks.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,16 @@ public static void init() {
}

public static Block bridgePillar=new BlockBridgePillar().setHardness(3.5F).setStepSound(Block.soundTypeWood);
public static Block distilIdle=new BlockDistil(2, false).setHardness(3.5F).setStepSound(Block.soundTypeStone);
public static Block distilActive=new BlockDistil(2,true).setHardness(3.5F).setStepSound(Block.soundTypeStone).setLightLevel(0.8F);

public static void loadBlocks() {
TraincraftRegistry.registerBlock(bridgePillar,Traincraft.tcTab, Info.modID,"bridgePillar");
TraincraftRegistry.registerBlock(distilIdle,Traincraft.tcTab, Info.modID,"distilIdle");
TraincraftRegistry.registerBlock(distilActive,null, Info.modID,"distilActive");

BlockIDs.distilIdle.block = new BlockDistil(2, false).setHardness(3.5F).setStepSound(Block.soundTypeStone);
BlockIDs.distilActive.block = new BlockDistil(2, true).setHardness(3.5F).setStepSound(Block.soundTypeStone).setLightLevel(0.8F);
//TCBlocks.distilIdle.block = new BlockDistil(2, false).setHardness(3.5F).setStepSound(Block.soundTypeStone);
//BlockIDs.distilActive.block = new BlockDistil(2, true).setHardness(3.5F).setStepSound(Block.soundTypeStone).setLightLevel(0.8F);
//BlockIDs.signal.block = new BlockSignal(BlockIDs.signal.block, 16).setHardness(1.7F).setStepSound(Block.soundTypeMetal);

BlockIDs.assemblyTableI.block = new BlockAssemblyTableI(Material.wood).setHardness(3.5F).setStepSound(Block.soundTypeWood);
Expand Down
32 changes: 26 additions & 6 deletions src/main/java/train/common/core/CreativeTabTraincraft.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,49 @@

package train.common.core;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.StatCollector;
import train.common.library.ItemIDs;
import train.common.library.TraincraftRegistry;

import java.util.List;

public class CreativeTabTraincraft extends CreativeTabs {
public Item tabItem;

public CreativeTabTraincraft(int par1, String par2Str) {
super(par1, par2Str);
/**instances the tab by handling it through the super.*/
public CreativeTabTraincraft(String name, String MODID, String textureName) {
super(CreativeTabs.getNextID(), name);
tabItem= TraincraftRegistry.RegisterItem(new Item(),MODID,textureName,null);
}

@Override
public ItemStack getIconItemStack() {
return new ItemStack(ItemIDs.minecartLocoBR80_DB.item);
return new ItemStack(tabItem);
}

@Override
public String getTranslatedTabLabel() {
return super.getTabLabel();
return StatCollector.translateToLocal(super.getTabLabel());
}

/**the icon for the tab. override this one*/
public Item getTabItem(){return tabItem;}

/**the icon for the tab. don't override this one*/
@Override
public Item getTabIconItem() {
return ItemIDs.minecartLocoBR80_DB.item;
return getTabItem();
}
}

/**This is used to hide items from the creative tab, but could also be used for sorting.*/
@SideOnly(Side.CLIENT)
public void displayAllReleventItems(List p_78018_1_) {
super.displayAllReleventItems(p_78018_1_);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import net.minecraft.item.ItemStack;
import net.minecraft.stats.Achievement;
import net.minecraftforge.common.AchievementPage;
import train.common.blocks.TCBlocks;
import train.common.library.AchievementIDs;
import train.common.library.BlockIDs;
import train.common.library.ItemIDs;
Expand Down Expand Up @@ -54,7 +55,7 @@ public static void load() {
AchievementIDs.dieselEngine.achievement = achievement("dieselEngine", -6, 4, ItemIDs.dieselengine.item, AchievementIDs.steel.achievement);
AchievementIDs.diesel.achievement = achievement("dieselLoco", -6, 6, ItemIDs.minecartCD742.item, AchievementIDs.dieselEngine.achievement);

AchievementIDs.distilationTower.achievement = achievement("distilationTower", -10, 0, BlockIDs.distilActive.block,null);
AchievementIDs.distilationTower.achievement = achievement("distilationTower", -10, 0, TCBlocks.distilActive,null);
AchievementIDs.dieselFuel.achievement = achievement("dieselFuel", -8, 2, ItemIDs.diesel.item, AchievementIDs.distilationTower.achievement);
AchievementIDs.plastic.achievement = achievement("plastic", -12, 2, ItemIDs.rawPlastic.item, AchievementIDs.distilationTower.achievement);
AchievementIDs.fineCopperWire.achievement = achievement("fineCopperWire", -12, 4, ItemIDs.copperWireFine.item, AchievementIDs.plastic.achievement);
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/train/common/core/handlers/RecipeHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public static void initBlockRecipes() {
addDictRecipe(new ItemStack(BlockIDs.trainWorkbench.block, 1), "###", "IFI", "###", '#', "plankWood", 'F', Blocks.furnace, 'I', ironingot);
}
}
addDictRecipe(new ItemStack(BlockIDs.distilIdle.block, 1), "###", "#F#", "###", '#', "ingotSteel", 'F', ItemIDs.firebox.item);
addDictRecipe(new ItemStack(TCBlocks.distilIdle, 1), "###", "#F#", "###", '#', "ingotSteel", 'F', ItemIDs.firebox.item);

/* Open Hearth Furnace */
if (!ConfigHandler.MAKE_MODPACKS_GREAT_AGAIN) {
Expand Down Expand Up @@ -433,7 +433,7 @@ public static void initItemRecipes() {

TrainCraftingManager.instance.addRecipe(new ItemStack(ItemIDs.composite_wrench.item, 1), "S S", " R ", " R ", 'R', ItemIDs.reinforcedPlastic.item, 'S', steelItem);
TrainCraftingManager.instance.addRecipe(new ItemStack(ItemIDs.steelcab.item, 2), "###", "X X", "XXX", 'X', steelItem, '#', plankItem);// Steel cab
TrainCraftingManager.instance.addRecipe(new ItemStack(BlockIDs.distilIdle.block, 1), "###", "#F#", "###", '#', steelItem, 'F', ItemIDs.firebox.item);
TrainCraftingManager.instance.addRecipe(new ItemStack(TCBlocks.distilIdle, 1), "###", "#F#", "###", '#', steelItem, 'F', ItemIDs.firebox.item);
for (ItemStack rs : redstone) {
TrainCraftingManager.instance.addRecipe(new ItemStack(ItemIDs.transformer.item, 1), "# #", "XEX", "###", '#', steelItem, 'E', ItemIDs.electronicCircuit.item, 'X', rs.getItem());// transformer
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/train/common/library/AchievementIDs.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import net.minecraft.item.Item;
import net.minecraft.stats.Achievement;
import train.common.blocks.TCBlocks;

public enum AchievementIDs {
steel(new Item[] { ItemIDs.steel.item }),
Expand Down Expand Up @@ -71,7 +72,7 @@ public enum AchievementIDs {
caboose(new Item[] { ItemIDs.minecartCaboose.item, ItemIDs.minecartCaboose3.item,
ItemIDs.minecartCabooseWork.item }),
stockCar(new Item[] { ItemIDs.minecartStockCar.item, ItemIDs.minecartDRWGStockCar.item }),
distilationTower(new Item[] { Item.getItemFromBlock(BlockIDs.distilIdle.block) }),
distilationTower(new Item[] { Item.getItemFromBlock(TCBlocks.distilIdle) }),
mtg(new Item[] {ItemIDs.minecartLUengine.item}),
massTransit(new Item[] { ItemIDs.minecartClass345engine.item, ItemIDs.minecartDstockEngine.item, ItemIDs.minecartLocoRenfe446Motor.item }),
cercanias(new Item[] { ItemIDs.minecartLocoRenfe446Motor.item,}),
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/train/common/library/BlockIDs.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ public enum BlockIDs {
assemblyTableII(false, null),
assemblyTableIII(false, null),

distilIdle(false, null),
distilActive(false, null),
signal(false, null),

//book(true, ItemBlockBook.class),
Expand Down
20 changes: 20 additions & 0 deletions src/main/java/train/common/tile/TileEntityDistil.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,25 @@

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import ebf.tim.utility.CommonUtil;
import ebf.tim.utility.DebugUtil;
import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.texture.ITickable;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntityFurnace;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.*;
import train.common.api.LiquidManager;
import train.common.api.LiquidManager.StandardTank;
import train.common.api.blocks.TileTraincraft;
import train.common.blocks.BlockDistil;
import train.common.blocks.TCBlocks;
import train.common.library.BlockIDs;
import train.common.library.Info;
import train.common.recipes.DistilRecipes;

import java.util.Random;
Expand Down Expand Up @@ -112,6 +119,11 @@ public boolean isBurning() {
return distilBurnTime > 0;
}

@Override
public boolean canUpdate()
{
return true;
}
@Override
public void updateEntity() {
if(!worldObj.isRemote){
Expand Down Expand Up @@ -245,6 +257,7 @@ else if (slots[i].stackSize < itemstack1.getMaxStackSize()) {
}

private boolean canSmelt() {
DebugUtil.println(slots[0] == null);
if (slots[0] == null || (slots[3] != null && slots[3].stackSize==64) || (slots[4] != null && slots[4].stackSize==64)) {
return false;
}
Expand Down Expand Up @@ -379,4 +392,11 @@ public boolean canExtractItem(int slot, ItemStack stack, int side){
return side != 1 && slot == 3;
}

@Override
@SideOnly(Side.CLIENT)
public ResourceLocation getTexture(int x, int y, int z){
return new ResourceLocation(Info.modID,
(worldObj==null|| CommonUtil.getBlockAt(Minecraft.getMinecraft().theWorld,x,y,z)== TCBlocks.distilActive)?
"textures/blocks/distil_on.png":"textures/blocks/distil_off.png");
}
}
4 changes: 2 additions & 2 deletions src/main/resources/assets/tc/lang/en_US.lang
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ tile.tc:stopper.name=Train Buffer
tile.tc:embeddedStopper.name=Embedded Train Buffer
tile.tc:americanstopper.name=Hayes Train Buffer
tile.tc:trainWorkbench.name=Train Workbench
tile.tc:distilActive.name=Distill (active)
tile.tc:distilIdle.name=Distill
tile.distilActive.name=Distill (active)
tile.distilIdle.name=Distill
tile.tc:assemblyTableI.name=Assembly Table I
tile.tc:assemblyTableII.name=Assembly Table II
tile.tc:assemblyTableIII.name=Assembly Table III
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit da91cbc

Please sign in to comment.