mirror of
https://github.com/HbmMods/Hbm-s-Nuclear-Tech-GIT.git
synced 2026-01-25 10:32:49 +00:00
steel crate minecart for some reason
This commit is contained in:
parent
9f7c95f79b
commit
72051a71fc
@ -0,0 +1,143 @@
|
||||
package com.hbm.entity.item;
|
||||
|
||||
import net.minecraft.entity.item.EntityMinecart;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
/**
|
||||
* Only exists because some absolute genius at mojang thought it'd be funny to have the base class' stack array be fixed at 36.
|
||||
* Yes, 36. No more, no less. Hopper carts use it too, it's just that IInventory caps the accessible slots at 5. Amazing, isn't it?
|
||||
* @author hbm
|
||||
*
|
||||
*/
|
||||
public abstract class EntityMinecartContainerBase extends EntityMinecart implements IInventory {
|
||||
|
||||
protected ItemStack[] slots = new ItemStack[this.getSizeInventory()];
|
||||
|
||||
public EntityMinecartContainerBase(World p_i1712_1_) {
|
||||
super(p_i1712_1_);
|
||||
}
|
||||
|
||||
public EntityMinecartContainerBase(World world, double x, double y, double z) {
|
||||
super(world, x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlot(int slot) {
|
||||
return slots[slot];
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack decrStackSize(int slot, int amount) {
|
||||
if(this.slots[slot] != null) {
|
||||
ItemStack itemstack;
|
||||
|
||||
if(this.slots[slot].stackSize <= amount) {
|
||||
itemstack = this.slots[slot];
|
||||
this.slots[slot] = null;
|
||||
return itemstack;
|
||||
} else {
|
||||
itemstack = this.slots[slot].splitStack(amount);
|
||||
|
||||
if(this.slots[slot].stackSize == 0) {
|
||||
this.slots[slot] = null;
|
||||
}
|
||||
|
||||
return itemstack;
|
||||
}
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlotOnClosing(int slot) {
|
||||
if(this.slots[slot] != null) {
|
||||
ItemStack itemstack = this.slots[slot];
|
||||
this.slots[slot] = null;
|
||||
return itemstack;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInventorySlotContents(int slot, ItemStack stack) {
|
||||
this.slots[slot] = stack;
|
||||
|
||||
if(stack != null && stack.stackSize > this.getInventoryStackLimit()) {
|
||||
stack.stackSize = this.getInventoryStackLimit();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInventoryName() {
|
||||
return this.hasCustomInventoryName() ? this.func_95999_t() : "container.minecart";
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInventoryStackLimit() {
|
||||
return 64;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markDirty() { }
|
||||
|
||||
@Override
|
||||
public boolean isUseableByPlayer(EntityPlayer player) {
|
||||
return this.isDead ? false : player.getDistanceSqToEntity(this) <= 64.0D;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openInventory() { }
|
||||
|
||||
@Override
|
||||
public void closeInventory() { }
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot(int slot, ItemStack stack) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMinecartType() {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void writeEntityToNBT(NBTTagCompound nbt) {
|
||||
super.writeEntityToNBT(nbt);
|
||||
NBTTagList nbttaglist = new NBTTagList();
|
||||
|
||||
for(int i = 0; i < this.slots.length; ++i) {
|
||||
if(this.slots[i] != null) {
|
||||
NBTTagCompound nbttagcompound1 = new NBTTagCompound();
|
||||
nbttagcompound1.setByte("Slot", (byte) i);
|
||||
this.slots[i].writeToNBT(nbttagcompound1);
|
||||
nbttaglist.appendTag(nbttagcompound1);
|
||||
}
|
||||
}
|
||||
|
||||
nbt.setTag("Items", nbttaglist);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void readEntityFromNBT(NBTTagCompound nbt) {
|
||||
super.readEntityFromNBT(nbt);
|
||||
NBTTagList nbttaglist = nbt.getTagList("Items", 10);
|
||||
this.slots = new ItemStack[this.getSizeInventory()];
|
||||
|
||||
for(int i = 0; i < nbttaglist.tagCount(); ++i) {
|
||||
NBTTagCompound nbttagcompound1 = nbttaglist.getCompoundTagAt(i);
|
||||
int j = nbttagcompound1.getByte("Slot") & 255;
|
||||
|
||||
if(j >= 0 && j < this.slots.length) {
|
||||
this.slots[j] = ItemStack.loadItemStackFromNBT(nbttagcompound1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
47
src/main/java/com/hbm/entity/item/EntityMinecartCrate.java
Normal file
47
src/main/java/com/hbm/entity/item/EntityMinecartCrate.java
Normal file
@ -0,0 +1,47 @@
|
||||
package com.hbm.entity.item;
|
||||
|
||||
import com.hbm.blocks.ModBlocks;
|
||||
import com.hbm.items.ModItems;
|
||||
import com.hbm.main.MainRegistry;
|
||||
|
||||
import cpw.mods.fml.common.network.internal.FMLNetworkHandler;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class EntityMinecartCrate extends EntityMinecartContainerBase {
|
||||
|
||||
public EntityMinecartCrate(World world) {
|
||||
super(world);
|
||||
}
|
||||
|
||||
public EntityMinecartCrate(World world, double x, double y, double z) {
|
||||
super(world, x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean interactFirst(EntityPlayer player) {
|
||||
if(net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(new net.minecraftforge.event.entity.minecart.MinecartInteractEvent(this, player)))
|
||||
return true;
|
||||
if(!this.worldObj.isRemote) {
|
||||
FMLNetworkHandler.openGui(player, MainRegistry.instance, ModItems.guiID_cart_crate, worldObj, this.getEntityId(), 0, 0);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Block func_145817_o() {
|
||||
return ModBlocks.crate_steel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSizeInventory() {
|
||||
return 9 * 6;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMinecartType() {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@ -3,6 +3,7 @@ package com.hbm.handler;
|
||||
import com.hbm.blocks.ModBlocks;
|
||||
import com.hbm.blocks.generic.BlockBobble.TileEntityBobble;
|
||||
import com.hbm.blocks.machine.NTMAnvil;
|
||||
import com.hbm.entity.item.EntityMinecartCrate;
|
||||
import com.hbm.interfaces.Spaghetti;
|
||||
import com.hbm.inventory.container.*;
|
||||
import com.hbm.inventory.gui.*;
|
||||
@ -862,6 +863,8 @@ public class GUIHandler implements IGuiHandler {
|
||||
return new ContainerLeadBox(player, player.inventory, new InventoryLeadBox(player.getHeldItem()));
|
||||
case ModItems.guiID_item_book:
|
||||
return new ContainerBook(player.inventory);
|
||||
case ModItems.guiID_cart_crate:
|
||||
return new ContainerCrateSteel(player.inventory, (EntityMinecartCrate)player.worldObj.getEntityByID(x));
|
||||
}
|
||||
|
||||
return null;
|
||||
@ -1725,6 +1728,8 @@ public class GUIHandler implements IGuiHandler {
|
||||
return new GUIScreenHolotape();
|
||||
case ModItems.guiID_item_fluid:
|
||||
return new GUIScreenFluid(player);
|
||||
case ModItems.guiID_cart_crate:
|
||||
return new GUICrateSteel(player.inventory, (EntityMinecartCrate) player.worldObj.getEntityByID(x));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -1,19 +1,18 @@
|
||||
package com.hbm.inventory.container;
|
||||
|
||||
import com.hbm.tileentity.machine.storage.TileEntityCrateSteel;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
//@invtweaks.api.container.ChestContainer
|
||||
public class ContainerCrateSteel extends Container {
|
||||
|
||||
private TileEntityCrateSteel diFurnace;
|
||||
private IInventory diFurnace;
|
||||
|
||||
public ContainerCrateSteel(InventoryPlayer invPlayer, TileEntityCrateSteel tedf) {
|
||||
public ContainerCrateSteel(InventoryPlayer invPlayer, IInventory tedf) {
|
||||
diFurnace = tedf;
|
||||
|
||||
for(int i = 0; i < 6; i++) {
|
||||
|
||||
@ -4,22 +4,22 @@ import org.lwjgl.opengl.GL11;
|
||||
|
||||
import com.hbm.inventory.container.ContainerCrateSteel;
|
||||
import com.hbm.lib.RefStrings;
|
||||
import com.hbm.tileentity.machine.storage.TileEntityCrateSteel;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
public class GUICrateSteel extends GuiContainer {
|
||||
|
||||
private static ResourceLocation texture = new ResourceLocation(RefStrings.MODID + ":textures/gui/gui_crate_steel.png");
|
||||
private TileEntityCrateSteel diFurnace;
|
||||
private IInventory crate;
|
||||
|
||||
public GUICrateSteel(InventoryPlayer invPlayer, TileEntityCrateSteel tedf) {
|
||||
super(new ContainerCrateSteel(invPlayer, tedf));
|
||||
diFurnace = tedf;
|
||||
public GUICrateSteel(InventoryPlayer invPlayer, IInventory inv) {
|
||||
super(new ContainerCrateSteel(invPlayer, inv));
|
||||
crate = inv;
|
||||
|
||||
this.xSize = 176;
|
||||
this.ySize = 222;
|
||||
@ -27,7 +27,7 @@ public class GUICrateSteel extends GuiContainer {
|
||||
|
||||
@Override
|
||||
protected void drawGuiContainerForegroundLayer(int i, int j) {
|
||||
String name = this.diFurnace.hasCustomInventoryName() ? this.diFurnace.getInventoryName() : I18n.format(this.diFurnace.getInventoryName());
|
||||
String name = this.crate.hasCustomInventoryName() ? this.crate.getInventoryName() : I18n.format(this.crate.getInventoryName());
|
||||
|
||||
this.fontRendererObj.drawString(name, this.xSize / 2 - this.fontRendererObj.getStringWidth(name) / 2, 6, 4210752);
|
||||
this.fontRendererObj.drawString(I18n.format("container.inventory"), 8, this.ySize - 96 + 2, 4210752);
|
||||
|
||||
@ -16,7 +16,7 @@ import net.minecraft.util.IIcon;
|
||||
public class ItemEnumMulti extends Item {
|
||||
|
||||
//hell yes, now we're thinking with enums!
|
||||
private Class<? extends Enum> theEnum;
|
||||
protected Class<? extends Enum> theEnum;
|
||||
private boolean multiName;
|
||||
private boolean multiTexture;
|
||||
|
||||
|
||||
@ -999,6 +999,8 @@ public class ModItems {
|
||||
public static Item canned_bark;
|
||||
public static Item can_key;
|
||||
|
||||
public static Item cart;
|
||||
|
||||
public static Item coin_creeper;
|
||||
public static Item coin_radiation;
|
||||
public static Item coin_maskman;
|
||||
@ -2552,6 +2554,8 @@ public class ModItems {
|
||||
public static final int guiID_item_bobble = 10107;
|
||||
public static final int guiID_item_holo_image = 10108;
|
||||
|
||||
public static final int guiID_cart_crate = 2000;
|
||||
|
||||
public static Item mysteryshovel;
|
||||
public static Item memory;
|
||||
|
||||
@ -3537,6 +3541,8 @@ public class ModItems {
|
||||
canned_bark = new ItemLemon(2, 5, false).setUnlocalizedName("canned_bark").setCreativeTab(MainRegistry.consumableTab).setTextureName(RefStrings.MODID + ":canned_bark");
|
||||
can_key = new Item().setUnlocalizedName("can_key").setCreativeTab(MainRegistry.consumableTab).setTextureName(RefStrings.MODID + ":can_key");
|
||||
|
||||
cart = new ItemModMinecart().setUnlocalizedName("cart").setCreativeTab(MainRegistry.consumableTab).setTextureName(RefStrings.MODID + ":cart");
|
||||
|
||||
coin_creeper = new ItemCustomLore().setRarity(EnumRarity.uncommon).setUnlocalizedName("coin_creeper").setCreativeTab(MainRegistry.consumableTab).setTextureName(RefStrings.MODID + ":coin_creeper");
|
||||
coin_radiation = new ItemCustomLore().setRarity(EnumRarity.uncommon).setUnlocalizedName("coin_radiation").setCreativeTab(MainRegistry.consumableTab).setTextureName(RefStrings.MODID + ":coin_radiation");
|
||||
coin_maskman = new ItemCustomLore().setRarity(EnumRarity.uncommon).setUnlocalizedName("coin_maskman").setCreativeTab(MainRegistry.consumableTab).setTextureName(RefStrings.MODID + ":coin_maskman");
|
||||
@ -7785,6 +7791,9 @@ public class ModItems {
|
||||
GameRegistry.registerItem(shackles, shackles.getUnlocalizedName());
|
||||
GameRegistry.registerItem(injector_5htp, injector_5htp.getUnlocalizedName());
|
||||
GameRegistry.registerItem(injector_knife, injector_knife.getUnlocalizedName());
|
||||
|
||||
//Minecarts
|
||||
GameRegistry.registerItem(cart, cart.getUnlocalizedName());
|
||||
|
||||
//The Gadget
|
||||
GameRegistry.registerItem(gadget_explosive, gadget_explosive.getUnlocalizedName());
|
||||
|
||||
101
src/main/java/com/hbm/items/tool/ItemModMinecart.java
Normal file
101
src/main/java/com/hbm/items/tool/ItemModMinecart.java
Normal file
@ -0,0 +1,101 @@
|
||||
package com.hbm.items.tool;
|
||||
|
||||
import com.hbm.entity.item.EntityMinecartCrate;
|
||||
import com.hbm.items.ItemEnumMulti;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockDispenser;
|
||||
import net.minecraft.block.BlockRailBase;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.dispenser.BehaviorDefaultDispenseItem;
|
||||
import net.minecraft.dispenser.IBehaviorDispenseItem;
|
||||
import net.minecraft.dispenser.IBlockSource;
|
||||
import net.minecraft.entity.item.EntityMinecart;
|
||||
import net.minecraft.entity.item.EntityMinecartEmpty;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class ItemModMinecart extends ItemEnumMulti {
|
||||
|
||||
public static enum EnumMinecart {
|
||||
CRATE
|
||||
}
|
||||
|
||||
public ItemModMinecart() {
|
||||
super(EnumMinecart.class, true, true);
|
||||
this.maxStackSize = 1;
|
||||
this.setCreativeTab(CreativeTabs.tabTransport);
|
||||
BlockDispenser.dispenseBehaviorRegistry.putObject(this, dispenseBehavior);
|
||||
}
|
||||
|
||||
private static final IBehaviorDispenseItem dispenseBehavior = new BehaviorDefaultDispenseItem() {
|
||||
private final BehaviorDefaultDispenseItem behaviourDefaultDispenseItem = new BehaviorDefaultDispenseItem();
|
||||
|
||||
public ItemStack dispenseStack(IBlockSource source, ItemStack stack) {
|
||||
EnumFacing enumfacing = BlockDispenser.func_149937_b(source.getBlockMetadata());
|
||||
World world = source.getWorld();
|
||||
double x = source.getX() + enumfacing.getFrontOffsetX() * 1.125D;
|
||||
double y = source.getY() + enumfacing.getFrontOffsetY() * 1.125D;
|
||||
double z = source.getZ() + enumfacing.getFrontOffsetZ() * 1.125D;
|
||||
int iX = source.getXInt() + enumfacing.getFrontOffsetX();
|
||||
int iY = source.getYInt() + enumfacing.getFrontOffsetY();
|
||||
int iZ = source.getZInt() + enumfacing.getFrontOffsetZ();
|
||||
Block block = world.getBlock(iX, iY, iZ);
|
||||
double yOffset;
|
||||
|
||||
if(BlockRailBase.func_150051_a(block)) {
|
||||
yOffset = 0.0D;
|
||||
} else {
|
||||
if(block.getMaterial() != Material.air || !BlockRailBase.func_150051_a(world.getBlock(iX, iY - 1, iZ))) {
|
||||
return this.behaviourDefaultDispenseItem.dispense(source, stack);
|
||||
}
|
||||
|
||||
yOffset = -1.0D;
|
||||
}
|
||||
|
||||
EntityMinecart entityminecart = createMinecart(world, x, y + yOffset, z, (EnumMinecart) EnumMinecart.values()[stack.getItemDamage()]);
|
||||
|
||||
if(stack.hasDisplayName()) {
|
||||
entityminecart.setMinecartName(stack.getDisplayName());
|
||||
}
|
||||
|
||||
world.spawnEntityInWorld(entityminecart);
|
||||
stack.splitStack(1);
|
||||
return stack;
|
||||
}
|
||||
|
||||
protected void playDispenseSound(IBlockSource source) {
|
||||
source.getWorld().playAuxSFX(1000, source.getXInt(), source.getYInt(), source.getZInt(), 0);
|
||||
}
|
||||
};
|
||||
|
||||
public boolean onItemUse(ItemStack stack, EntityPlayer entity, World world, int x, int y, int z, int side, float fx, float fy, float fz) {
|
||||
if(BlockRailBase.func_150051_a(world.getBlock(x, y, z))) {
|
||||
if(!world.isRemote) {
|
||||
|
||||
EntityMinecart entityminecart = createMinecart(world, x + 0.5D, y + 0.5D, z + 0.5D, (EnumMinecart) this.theEnum.getEnumConstants()[stack.getItemDamage()]);
|
||||
|
||||
if(stack.hasDisplayName()) {
|
||||
entityminecart.setMinecartName(stack.getDisplayName());
|
||||
}
|
||||
|
||||
world.spawnEntityInWorld(entityminecart);
|
||||
}
|
||||
|
||||
--stack.stackSize;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static EntityMinecart createMinecart(World world, double x, double y, double z, EnumMinecart type) {
|
||||
switch(type) {
|
||||
case CRATE: return new EntityMinecartCrate(world, x, y, z);
|
||||
default: return new EntityMinecartEmpty(world, x, y, z);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -11,6 +11,7 @@ import net.minecraft.client.particle.EntityFX;
|
||||
import net.minecraft.client.particle.EntityFireworkSparkFX;
|
||||
import net.minecraft.client.particle.EntityFlameFX;
|
||||
import net.minecraft.client.particle.EntityReddustFX;
|
||||
import net.minecraft.client.renderer.entity.RenderMinecart;
|
||||
import net.minecraft.client.renderer.entity.RenderSnowball;
|
||||
import net.minecraft.client.renderer.texture.TextureManager;
|
||||
import net.minecraft.entity.Entity;
|
||||
@ -622,6 +623,7 @@ public class ClientProxy extends ServerProxy {
|
||||
RenderingRegistry.registerEntityRenderingHandler(EntitySpear.class, new RenderSpear());
|
||||
//minecarts
|
||||
RenderingRegistry.registerEntityRenderingHandler(EntityMinecartTest.class, new RenderMinecartTest());
|
||||
RenderingRegistry.registerEntityRenderingHandler(EntityMinecartCrate.class, new RenderMinecart());
|
||||
//items
|
||||
RenderingRegistry.registerEntityRenderingHandler(EntityMovingItem.class, new RenderMovingItem());
|
||||
RenderingRegistry.registerEntityRenderingHandler(EntityTNTPrimedBase.class, new RenderTNTPrimedBase());
|
||||
|
||||
@ -491,6 +491,7 @@ public class MainRegistry {
|
||||
EntityRegistry.registerModEntity(EntityTNTPrimedBase.class, "entity_ntm_tnt_primed", 166, this, 1000, 1, true);
|
||||
EntityRegistry.registerModEntity(EntityGrenadeBouncyGeneric.class, "entity_grenade_generic", 168, this, 250, 1, true);
|
||||
EntityRegistry.registerModEntity(EntityGrenadeImpactGeneric.class, "entity_grenade_generic", 169, this, 250, 1, true);
|
||||
EntityRegistry.registerModEntity(EntityMinecartCrate.class, "entity_ntm_cart_crate", 170, this, 250, 1, true);
|
||||
|
||||
EntityRegistry.registerGlobalEntityID(EntityNuclearCreeper.class, "entity_mob_nuclear_creeper", EntityRegistry.findGlobalUniqueEntityId(), 0x204131, 0x75CE00);
|
||||
EntityRegistry.registerGlobalEntityID(EntityTaintedCreeper.class, "entity_mob_tainted_creeper", EntityRegistry.findGlobalUniqueEntityId(), 0x813b9b, 0xd71fdd);
|
||||
|
||||
BIN
src/main/resources/assets/hbm/textures/items/cart.crate.png
Normal file
BIN
src/main/resources/assets/hbm/textures/items/cart.crate.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 430 B |
Loading…
x
Reference in New Issue
Block a user