got 1.11 working but rotation is wrong

This commit is contained in:
Mohammad-Ali Minaie
2016-12-26 21:25:55 -05:00
parent 9126a443f6
commit bd5c334ce9
89 changed files with 3754 additions and 1262 deletions

BIN
1.11/src/.DS_Store vendored Normal file

Binary file not shown.

BIN
1.11/src/main/.DS_Store vendored Normal file

Binary file not shown.

View File

@@ -2,9 +2,13 @@ package nmd.primal.forgecraft;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.*;
import net.minecraft.world.World;
import net.minecraftforge.common.util.FakePlayer;
import net.minecraftforge.fml.common.registry.GameRegistry;
/**
@@ -38,4 +42,14 @@ public class CommonUtils {
if (item == Items.BLAZE_POWDER) return 800;
return GameRegistry.getFuelValue(stack);
}
public static void spawnItemEntity(World world, EntityPlayer player, ItemStack stack)
{
EntityItem entityitem = new EntityItem(world, player.posX, player.posY, player.posZ, stack); // player.posY - 1.0D
world.spawnEntity(entityitem);
if (!(player instanceof FakePlayer))
entityitem.onCollideWithPlayer(player);
}
}

View File

@@ -2,6 +2,7 @@ package nmd.primal.forgecraft;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fml.client.config.GuiConfigEntries;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.relauncher.Side;
@@ -21,7 +22,7 @@ public class ModInfo {
//public static final String MOD_PREFIX = MOD_ID + ":";
//public static final String MOD_CHANNEL = MOD_ID;
public static final String MOD_VERSION = "1.0.1";
public static final String MC_VERSIONS = "[1.9.4, 1.11.0)";
public static final String MC_VERSIONS = "[1.9.4, 1.11.2)";
/** Mod Structures **/
public static final String SERVER_PROXY = "nmd.primal.forgecraft.proxy.ServerProxy";
@@ -74,8 +75,23 @@ public class ModInfo {
{
@Override
@SideOnly(Side.CLIENT)
public Item getTabIconItem() {
return Item.getItemFromBlock(ModBlocks.firebox);
public ItemStack getTabIconItem() {
return new ItemStack(ModBlocks.firebox);
}
};
/*
public static CreativeTabs TAB_PRIMAL = new CreativeTabs(MOD_ID)
{
@Override
@SideOnly(Side.CLIENT)
public ItemStack getTabIconItem() {
return new ItemStack(PrimalItems.FLINT_HATCHET);
}
};
*/
}

View File

@@ -59,7 +59,7 @@ public class Firebox extends CustomContainerFacing implements ITileEntityProvide
}
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, @Nullable ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ)
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
{
if (!world.isRemote)
{
@@ -68,7 +68,7 @@ public class Firebox extends CustomContainerFacing implements ITileEntityProvide
{
ItemStack playerStack = player.getHeldItemMainhand();
Item playerItem;
ItemStack tileStack = tile.getStackInSlot(0);
ItemStack tileStack = tile.getSlotStack(0);
if(playerStack != null){
playerItem = playerStack.getItem();
@@ -86,13 +86,13 @@ public class Firebox extends CustomContainerFacing implements ITileEntityProvide
}
}
}
if(tile.getStackInSlot(0)!=null){
if(tile.getSlotStack(0)!=ItemStack.EMPTY){
if(CommonUtils.getVanillaItemBurnTime(playerStack) > 0) {
if (tileStack.getItem() == playerItem && tileStack.getItemDamage() == playerStack.getItemDamage()) {
//tile.setInventorySlotContents(0, playerStack);
ItemStack tempStack = new ItemStack(tileStack.getItem(), tileStack.stackSize + 1, tileStack.getItemDamage());
if(tileStack.stackSize < 64) {
tile.setInventorySlotContents(0, tempStack);
ItemStack tempStack = new ItemStack(tileStack.getItem(), tileStack.getCount() + 1, tileStack.getItemDamage());
if(tileStack.getCount() < 64) {
tile.setSlotStack(0, tempStack);
player.inventory.decrStackSize(player.inventory.currentItem, 1);
//player.setHeldItem(EnumHand.MAIN_HAND, null);
tile.markDirty();
@@ -101,11 +101,11 @@ public class Firebox extends CustomContainerFacing implements ITileEntityProvide
}
}
}
if(tile.getStackInSlot(0)==null){
if(tile.getSlotStack(0)==ItemStack.EMPTY){
if(CommonUtils.getVanillaItemBurnTime(playerStack) > 0) {
if (playerItem != Items.FLINT_AND_STEEL || playerItem != Item.getItemFromBlock(Blocks.TORCH)) {
tile.setInventorySlotContents(0, playerStack);
player.setHeldItem(EnumHand.MAIN_HAND, null);
tile.setSlotStack(0, playerStack);
player.setHeldItem(EnumHand.MAIN_HAND, ItemStack.EMPTY);
tile.markDirty();
world.notifyBlockUpdate(pos, state, state, 2);
}
@@ -115,13 +115,13 @@ public class Firebox extends CustomContainerFacing implements ITileEntityProvide
if(tileStack != null && playerStack == null && player.isSneaking()){
if(state.getValue(ACTIVE)==true){
world.setBlockState(pos, state.withProperty(ACTIVE, false), 2);
ItemStack returnStack = new ItemStack(tileStack.getItem(), tileStack.stackSize - 1);
ItemStack returnStack = new ItemStack(tileStack.getItem(), tileStack.getCount() - 1);
player.setHeldItem(EnumHand.MAIN_HAND, returnStack);
tile.markDirty();
world.notifyBlockUpdate(pos, state, state, 2);
} else {
player.setHeldItem(EnumHand.MAIN_HAND, tileStack);
tile.setInventorySlotContents(0, null);
tile.setSlotStack(0, ItemStack.EMPTY);
tile.markDirty();
world.notifyBlockUpdate(pos, state, state, 2);
}
@@ -133,9 +133,10 @@ public class Firebox extends CustomContainerFacing implements ITileEntityProvide
if(playerStack == null) {
if (tileStack != null) {
ItemStack tempStack1 = new ItemStack(tileStack.getItem(), 1, tileStack.getItemDamage());
ItemStack resetStack = new ItemStack(tileStack.getItem(), tileStack.stackSize - 1, tileStack.getItemDamage());
world.spawnEntityInWorld(new EntityItem(world, player.posX, player.posY, player.posZ, tempStack1));
tile.setInventorySlotContents(0,resetStack);
ItemStack resetStack = new ItemStack(tileStack.getItem(), tileStack.getCount() - 1, tileStack.getItemDamage());
CommonUtils.spawnItemEntity(world, player, tempStack1);
//world.spawnEntityInWorld(new EntityItem(world, player.posX, player.posY, player.posZ, tempStack1));
tile.setSlotStack(0,resetStack);
world.notifyBlockUpdate(pos, state, state, 2);
}
}
@@ -146,57 +147,7 @@ public class Firebox extends CustomContainerFacing implements ITileEntityProvide
}
public void onBlockClicked(World world, BlockPos pos, EntityPlayer player) {
/*if(!world.isRemote){
TileFirebox tile = (TileFirebox) world.getTileEntity(pos);
IBlockState state = world.getBlockState(pos);
if (tile != null) {
ItemStack playerStack = player.getHeldItemMainhand();
Item playerItem;
ItemStack tileStack = tile.getStackInSlot(0);
if (!player.isSneaking()) {
if( tileStack !=null) {
if (playerStack == null) {
ItemStack tempStack1 = tileStack;
ItemStack tempStack2 = tileStack;
tempStack1.stackSize = 1;
tempStack2.stackSize = tileStack.stackSize - 1;
System.out.println(tileStack.stackSize + "|" + "|" + tempStack2.stackSize);
//int tileSize = tile.decrStackSize()
//ItemStack tempReset = new ItemStack(tileStack.getItem(), tileSize - 1, tileStack.getItemDamage());
//System.out.println(tileSize + "|" + tempReset.stackSize);
world.spawnEntityInWorld(new EntityItem(world, player.posX, player.posY, player.posZ, tempStack1));
tile.setInventorySlotContents(0, tempStack2);
world.notifyBlockUpdate(pos, state, state, 2);
}
}
}
//RETURN THE WHOLE STACK
if (playerStack == null && player.isSneaking()) {
if (tileStack != null) {
if(state.getValue(ACTIVE)) {
ItemStack tempStack = new ItemStack(tileStack.getItem(), tileStack.stackSize - 1, tileStack.getItemDamage());
world.spawnEntityInWorld(new EntityItem(world, player.posX, player.posY, player.posZ, tempStack));
tile.setInventorySlotContents(0, null);
world.notifyBlockUpdate(pos, state, state, 2);
} else {
world.spawnEntityInWorld(new EntityItem(world, player.posX, player.posY, player.posZ, tileStack));
tile.setInventorySlotContents(0, null);
world.notifyBlockUpdate(pos, state, state, 2);
}
}
}
//RETURN 1
}
}*/
}
@Override
@@ -225,7 +176,7 @@ public class Firebox extends CustomContainerFacing implements ITileEntityProvide
{
if(!world.isRemote){
TileFirebox tile = (TileFirebox) world.getTileEntity(pos);
if(tile.getStackInSlot(0) != null){
if(tile.getSlotStack(0) != ItemStack.EMPTY){
if(world.getBlockState(pos).getValue(ACTIVE)==true){
return true;
}
@@ -239,34 +190,34 @@ public class Firebox extends CustomContainerFacing implements ITileEntityProvide
* Called serverside after this block is replaced with another in Chunk, but before the Tile Entity is updated
*/
@Override
public void breakBlock(World worldIn, BlockPos pos, IBlockState state)
public void breakBlock(World world, BlockPos pos, IBlockState state)
{
if (!worldIn.isRemote && worldIn.getGameRules().getBoolean("doTileDrops"))
if (!world.isRemote && world.getGameRules().getBoolean("doTileDrops"))
{
TileEntity tileentity = worldIn.getTileEntity(pos);
if (tileentity instanceof TileFirebox)
TileFirebox tile = (TileFirebox) world.getTileEntity(pos);
if (tile !=null)
{
InventoryHelper.dropInventoryItems(worldIn, pos, (TileFirebox)tileentity);
worldIn.updateComparatorOutputLevel(pos, this);
for (ItemStack stack : tile.getSlotList())
{
if (stack != null) {
float offset = 0.7F;
double offsetX = world.rand.nextFloat() * offset + (1.0F - offset) * 0.5D;
double offsetY = world.rand.nextFloat() * offset + (1.0F - offset) * 0.5D;
double offsetZ = world.rand.nextFloat() * offset + (1.0F - offset) * 0.5D;
EntityItem item = new EntityItem(world, pos.getX() + offsetX, pos.getY() + offsetY, pos.getZ() + offsetZ, stack);
item.setDefaultPickupDelay();
world.spawnEntity(item);
}
}
}
}
super.breakBlock(worldIn, pos, state);
}
@Override
public IBlockState onBlockPlaced(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer) {
IBlockState state = super.onBlockPlaced(worldIn, pos, facing, hitX, hitY, hitZ, meta, placer);
return state.withProperty(FACING, placer.getHorizontalFacing()).withProperty(ACTIVE, Boolean.valueOf(false));
super.breakBlock(world, pos, state);
}
@Override
public void onBlockPlacedBy(World world, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack){
if (stack.hasDisplayName()){
((TileFirebox) world.getTileEntity(pos)).setCustomName(stack.getDisplayName());
}
System.out.println(state.getBlock().getMetaFromState(state));
}
@Override

View File

@@ -83,19 +83,19 @@ public class TileFireboxRender extends TileEntitySpecialRenderer<TileFirebox>
int bright = tile.getWorld().getCombinedLight(pos.up(), 0);
OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, bright % 65536, bright / 65536);
ItemStack stack = tile.getStackInSlot(0);
ItemStack stack = tile.getSlotStack(0);
if (stack != null) {
boolean is_block = stack.getItem() instanceof ItemBlock;
float height = -0.75f;
float scale = is_block ? 0.9F : 1.6F;
int stackSize = stack.stackSize;
int stackSize = stack.getCount();
GL11.glPushMatrix();
GL11.glTranslatef(translateX, height, translateZ);
GL11.glScalef(scale, scale, scale);
GL11.glRotatef(90.0F * rotation, 0.0F, 1.0F, 0.0F);
Integer temp = tile.getStackInSlot(0).stackSize;
Integer temp = tile.getSlotStack(0).getCount();
renderItem.renderItem(stack, renderItem.getItemModelMesher().getItemModel(stack));
GL11.glRotatef(180F, 1.0F, 0.0F, 0.0F);

View File

@@ -3,13 +3,14 @@ package nmd.primal.forgecraft.tiles;
import net.minecraft.block.state.IBlockState;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityLockable;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
/**
* Created by kitsu on 12/3/2016.
*/
public abstract class BaseTile extends TileEntity{
public abstract class BaseTile extends TileEntity {
@Override
public boolean shouldRefresh(World world, BlockPos pos, IBlockState oldState, IBlockState newSate)
@@ -17,6 +18,16 @@ public abstract class BaseTile extends TileEntity{
return oldState.getBlock() != newSate.getBlock();
}
public void updateBlock()
{
// might be good
//this.markDirty();
World world = this.getWorld();
IBlockState state = world.getBlockState(this.pos);
world.notifyBlockUpdate(this.pos, state, state, 3);
}
@Override
public void readFromNBT(NBTTagCompound nbt)
{

View File

@@ -0,0 +1,97 @@
package nmd.primal.forgecraft.tiles;
import net.minecraft.inventory.ItemStackHelper;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.NonNullList;
/**
* Created by mminaie on 12/25/16.
*/
public abstract class TileBaseSlot extends BaseTile {
private NonNullList<ItemStack> slotList = NonNullList.<ItemStack>withSize(4, ItemStack.EMPTY);
// ***************************************************************************** //
// Controls
// ***************************************************************************** //
// ***************************************************************************** //
// get
//
public NonNullList<ItemStack> getSlotList()
{
return this.slotList;
}
public ItemStack getSlotStack(int i)
{
return this.slotList.get(i);
}
public int getSlotListSize()
{
return slotList.size();
}
public int getSlotLimit()
{
//return ((ShelfBasic)this.getBlockType()).getShelfSize();
//return 1;
return 64;
}
public ItemStack decrStackSize(int index, int count)
{
return ItemStackHelper.getAndSplit(this.getSlotList(), index, count);
}
// ***************************************************************************** //
// set
//
public void setSlotStack(int index, ItemStack stack)
{
this.slotList.set(index, stack);
this.markDirty();
this.updateBlock();
}
public void clearSlots()
{
this.slotList.clear();
}
/**
public boolean replaceStack(int index, ItemStack stack)
{
if (stack != null && stack.getCount() <= this.getSlotLimit()) {
this.setSlotStack(index, stack);
return true;
}
return false;
} **/
// ***************************************************************************** //
// NBT
// ***************************************************************************** //
@Override
public NBTTagCompound readNBT(NBTTagCompound nbt)
{
//super.readNBT(nbt);
this.slotList = NonNullList.<ItemStack>withSize(this.getSlotListSize(), ItemStack.EMPTY);
ItemStackHelper.loadAllItems(nbt, this.slotList);
return nbt;
}
@Override
public NBTTagCompound writeNBT(NBTTagCompound nbt)
{
//super.writeNBT(nbt);
ItemStackHelper.saveAllItems(nbt, this.slotList);
return nbt;
}
}

View File

@@ -9,6 +9,8 @@ import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.ItemStackHelper;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
@@ -19,6 +21,7 @@ import net.minecraft.tileentity.TileEntityFurnace;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.ITickable;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.ILockableContainer;
import net.minecraft.world.World;
import net.minecraftforge.common.util.Constants;
import nmd.primal.forgecraft.CommonUtils;
@@ -33,19 +36,15 @@ import static nmd.primal.forgecraft.CommonUtils.getVanillaItemBurnTime;
/**
* Created by mminaie on 11/30/16.
*/
public class TileFirebox extends BaseTile implements IInventory, ITickable {
public class TileFirebox extends TileBaseSlot implements ITickable {
private ItemStack[] inventory = new ItemStack [0];
private String customName;
private int iteration = 0;
public TileFirebox() {
this.inventory = new ItemStack[this.getSizeInventory()];
}
@Override
public void update () {
if(!worldObj.isRemote){
if(!world.isRemote){
World world = this.getWorld();
this.iteration ++;
if(this.iteration == 200 ) {
@@ -54,14 +53,14 @@ public class TileFirebox extends BaseTile implements IInventory, ITickable {
IBlockState state = world.getBlockState(this.pos);
BlockPos abovePos = new BlockPos(this.getPos().getX(), this.getPos().getY()+1, this.getPos().getZ());
IBlockState aboveState = world.getBlockState(abovePos);
if (worldObj.getBlockState(this.getPos()).getValue(Firebox.ACTIVE)) {
if (this.getStackInSlot(0) == null) {
worldObj.setBlockState(this.getPos(), state.withProperty(Firebox.ACTIVE, false), 2);
if (world.getBlockState(this.getPos()).getValue(Firebox.ACTIVE)) {
if (this.getSlotStack(0) == ItemStack.EMPTY) {
world.setBlockState(this.getPos(), state.withProperty(Firebox.ACTIVE, false), 2);
this.markDirty();
world.notifyBlockUpdate(pos, state, state, 2);
} else {
if(this.getStackInSlot(0) != null) {
if (worldObj.rand.nextInt((int) Math.floor(getVanillaItemBurnTime(this.getStackInSlot(0)) / 20)) == 0) {
if(this.getSlotStack(0) != ItemStack.EMPTY) {
if (world.rand.nextInt((int) Math.floor(getVanillaItemBurnTime(this.getSlotStack(0)) / 20)) == 0) {
this.decrStackSize(0, 1);
this.markDirty();
world.notifyBlockUpdate(pos, state, state, 2);
@@ -86,206 +85,18 @@ public class TileFirebox extends BaseTile implements IInventory, ITickable {
}
}
/*if (worldObj.isRemote){
World world = this.getWorld();
if(this.getStackInSlot(0)!=null){
renderItem = new EntityItem(world, this.getPos().getX(), this.getPos().getY(), this.getPos().getZ(), this.getStackInSlot(0));
}
}*/
}
public String getCustomName() {
return customName;
}
public void setCustomName (String customName){
this.customName = customName;
}
@Override
public String getName(){
//if custName is true return this.customName if false return --v
// ? means if true : means if false
return this.hasCustomName() ? this.customName : "container.firebox";
}
@Override
public boolean hasCustomName() {
return this.customName != null && !this.customName.equals("");
}
public int getSizeInventory() {
public int getSlotLimit() {
return 1;
}
@Override
public ItemStack getStackInSlot(int index) {
if (index < 0 || index >= this.getSizeInventory())
return null;
return this.inventory[index];
}
@Override
public ItemStack decrStackSize(int index, int count) {
if (this.getStackInSlot(index) != null) {
ItemStack itemstack;
if (this.getStackInSlot(index).stackSize <= count) {
itemstack = this.getStackInSlot(index);
this.setInventorySlotContents(index, null);
this.markDirty();
return itemstack;
} else {
itemstack = this.getStackInSlot(index).splitStack(count);
if (this.getStackInSlot(index).stackSize <= 0) {
this.setInventorySlotContents(index, null);
} else {
//Just to show that changes happened
this.setInventorySlotContents(index, this.getStackInSlot(index));
}
this.markDirty();
return itemstack;
}
} else {
return null;
}
}
@Override
public void setInventorySlotContents(int index, ItemStack stack) {
if (index < 0 || index >= this.getSizeInventory()) {
return;
}
if (stack != null && stack.stackSize > this.getInventoryStackLimit()) {
stack.stackSize = this.getInventoryStackLimit();
}
if (stack != null && stack.stackSize == 0) {
stack = null;
}
this.inventory[index] = stack;
this.markDirty();
World world = this.getWorld();
IBlockState state = world.getBlockState(this.pos);
world.notifyBlockUpdate(this.pos, state, state, 3);
}
@Override
public ItemStack removeStackFromSlot(int index) {
ItemStack stack = this.getStackInSlot(index);
this.setInventorySlotContents(index, null);
ItemStack stack = this.getSlotStack(index);
this.setSlotStack(index, ItemStack.EMPTY);
return stack;
}
@Override
public int getInventoryStackLimit() {
return 64;
}
@Override
public boolean isUseableByPlayer(EntityPlayer player){
return this.worldObj.getTileEntity(this.getPos()) == this && player.getDistanceSq(this.pos.add(0.5, 0.5, 0.5f)) <= 64;
}
@Override
public void openInventory(EntityPlayer player) {
}
public void closeInventory(EntityPlayer player){
}
@Override
public boolean isItemValidForSlot(int index, ItemStack stack) {
return true;
}
public int getField(int id) {
return 0;
}
@Override
public void setField(int id, int value) {
}
@Override
public int getFieldCount() {
return 0;
}
@Override
public void clear() {
for(int i = 0; i < this.getSizeInventory(); i++){
this.setInventorySlotContents(i, null);
}
}
// ***************************************************************************** //
// NBT
// ***************************************************************************** //
@Override
public NBTTagCompound readNBT(NBTTagCompound nbt)
{
NBTTagList list = nbt.getTagList("Items", Constants.NBT.TAG_COMPOUND);
inventory = new ItemStack[this.getSizeInventory()];
for (int i = 0; i < list.tagCount(); ++i)
{
NBTTagCompound tag = list.getCompoundTagAt(i);
this.inventory[tag.getByte("slot")] = ItemStack.loadItemStackFromNBT(tag);
}
if (nbt.hasKey("CustomName", 8)) {
this.setCustomName(nbt.getString("CustomName"));
}
return nbt;
}
@Override
public NBTTagCompound writeNBT(NBTTagCompound nbt)
{
NBTTagList list = new NBTTagList();
///
// RackMatrix
///
for (int i = 0; i < this.getSizeInventory(); ++i)
{
if (inventory[i] != null) {
NBTTagCompound tag = new NBTTagCompound();
tag.setByte("slot", (byte) i);
inventory[i].writeToNBT(tag);
list.appendTag(tag);
}
}
nbt.setTag("Items", list);
return nbt;
}
@Override
public NBTTagCompound getUpdateTag()
{
return writeToNBT(new NBTTagCompound());
}
@Override
public SPacketUpdateTileEntity getUpdatePacket() {
return new SPacketUpdateTileEntity(this.pos, 0, this.writeToNBT(new NBTTagCompound()));
}
@Override
public void onDataPacket(NetworkManager net, SPacketUpdateTileEntity packet) {
this.readFromNBT(packet.getNbtCompound());
}
}

BIN
1.11/src/main/resources/.DS_Store vendored Normal file

Binary file not shown.

BIN
1.11/src/main/resources/assets/.DS_Store vendored Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.