More work on BaseDimDoor. Corrected mistake in CommonProxy.

This commit is contained in:
zangamj 2016-06-18 19:10:31 -04:00
parent e6cc4c292f
commit 563c950c17
3 changed files with 35 additions and 53 deletions

View file

@ -74,6 +74,7 @@ public class CommonProxy {
TileEntityDimDoor dimTile = (TileEntityDimDoor) tile; TileEntityDimDoor dimTile = (TileEntityDimDoor) tile;
dimTile.openOrClosed = door.isDoorOnRift(world, pos) && door.isUpperDoorBlock(state); dimTile.openOrClosed = door.isDoorOnRift(world, pos) && door.isUpperDoorBlock(state);
dimTile.orientation = state.getValue(BlockDoor.FACING).rotateY().getHorizontalIndex(); dimTile.orientation = state.getValue(BlockDoor.FACING).rotateY().getHorizontalIndex();
if(state.getValue(BlockDoor.OPEN)) dimTile.orientation |= 4;
dimTile.lockStatus = door.getLockStatus(world, pos); dimTile.lockStatus = door.getLockStatus(world, pos);
} }
} }

View file

@ -17,6 +17,7 @@ import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.BlockPos; import net.minecraft.util.BlockPos;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.MathHelper; import net.minecraft.util.MathHelper;
import net.minecraft.util.MovingObjectPosition; import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.IBlockAccess; import net.minecraft.world.IBlockAccess;
@ -36,66 +37,45 @@ public abstract class BaseDimDoor extends BlockDoor implements IDimDoor, ITileEn
} }
@Override @Override
public void onEntityCollidedWithBlock(World world, int x, int y, int z, Entity entity) public void onEntityCollidedWithBlock(World world, BlockPos pos, Entity entity) {
{ enterDimDoor(world, pos, entity);
this.enterDimDoor(world, x, y, z, entity);
} }
@Override @Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ) public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player,
{ EnumFacing side, float hitX, float hitY, float hitZ) {
ItemStack stack = player.inventory.getCurrentItem(); ItemStack stack = player.inventory.getCurrentItem();
if (stack != null && stack.getItem() instanceof ItemDDKey) if (stack != null && stack.getItem() instanceof ItemDDKey) {return false;}
{
return false;
}
if(!checkCanOpen(world, x, y, z, player)) if(!checkCanOpen(world, pos, player)) {return false;}
{
return false;
}
int metadata = this.func_150012_g(world, x, y, z); if(state.getValue(BlockDoor.HALF) == EnumDoorHalf.UPPER) {
int newMetadata = metadata & 7; pos = pos.down();
newMetadata ^= 4; state = world.getBlockState(pos);
if ((metadata & 8) == 0)
{
world.setBlockMetadataWithNotify(x, y, z, newMetadata, 2);
world.markBlockRangeForRenderUpdate(x, y, z, x, y, z);
}
else
{
world.setBlockMetadataWithNotify(x, y - 1, z, newMetadata, 2);
world.markBlockRangeForRenderUpdate(x, y - 1, z, x, y, z);
} }
world.playAuxSFXAtEntity(player, 1003, x, y, z, 0); if(state.getBlock() != this) return false;
return true; else {
state = state.cycleProperty(BlockDoor.OPEN);
world.setBlockState(pos, state, 2);
world.markBlockRangeForRenderUpdate(pos, pos.up());
world.playAuxSFXAtEntity(player, state.getValue(BlockDoor.OPEN) ? 1003 : 1006, pos, 0);
return true;
}
} }
@Override @Override
public void onBlockAdded(World world, int x, int y, int z) public void onBlockAdded(World world, BlockPos pos, IBlockState state) {
{ placeLink(world, pos);
this.placeLink(world, x, y, z); world.setTileEntity(pos, createNewTileEntity(world, 0));
world.setTileEntity(x, y, z, this.createNewTileEntity(world, world.getBlockMetadata(x, y, z))); updateAttachedTile(world, pos);
this.updateAttachedTile(world, x, y, z);
} }
//Called to update the render information on the tile entity. Could probably implement a data watcher, //Called to update the render information on the tile entity. Could probably implement a data watcher,
//but this works fine and is more versatile I think. //but this works fine and is more versatile I think.
public BaseDimDoor updateAttachedTile(World world, int x, int y, int z) public BaseDimDoor updateAttachedTile(World world, BlockPos pos) {
{ DimDoors.proxy.updateDoorTE(this, world, pos);
DimDoors.proxy.updateDoorTE(this, world, x, y, z);
TileEntity tile = world.getTileEntity(x, y, z);
if (tile instanceof TileEntityDimDoor)
{
int metadata = world.getBlockMetadata(x, y, z);
TileEntityDimDoor dimTile = (TileEntityDimDoor) tile;
dimTile.openOrClosed = isDoorOnRift(world, x, y, z) && isUpperDoorBlock(metadata);
dimTile.orientation = this.func_150012_g(world, x, y, z) & 7;
}
return this; return this;
} }
@ -304,7 +284,7 @@ public abstract class BaseDimDoor extends BlockDoor implements IDimDoor, ITileEn
} }
@Override @Override
public void enterDimDoor(World world, int x, int y, int z, Entity entity) public void enterDimDoor(World world, BlockPos pos, Entity entity)
{ {
// FX entities dont exist on the server // FX entities dont exist on the server
if (world.isRemote) if (world.isRemote)
@ -386,14 +366,14 @@ public abstract class BaseDimDoor extends BlockDoor implements IDimDoor, ITileEn
} }
public boolean checkCanOpen(World world, int x, int y, int z) public boolean checkCanOpen(World world, BlockPos pos)
{ {
return this.checkCanOpen(world, x, y, z, null); return this.checkCanOpen(world, pos, null);
} }
public boolean checkCanOpen(World world, int x, int y, int z, EntityPlayer player) public boolean checkCanOpen(World world, BlockPos pos, EntityPlayer player)
{ {
DimLink link = getLink(world, x, y, z); DimLink link = getLink(world, pos);
if(link==null||player==null) if(link==null||player==null)
{ {
return link==null; return link==null;

View file

@ -3,6 +3,7 @@ package com.zixiken.dimdoors.blocks;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.BlockPos;
import net.minecraft.world.World; import net.minecraft.world.World;
public interface IDimDoor public interface IDimDoor
@ -15,7 +16,7 @@ public interface IDimDoor
* @param z * @param z
* @param entity * @param entity
*/ */
public void enterDimDoor(World world, int x, int y, int z, Entity entity); public void enterDimDoor(World world, BlockPos pos, Entity entity);
/** /**
* called when a door is placed to determine how it will place a link * called when a door is placed to determine how it will place a link
@ -24,11 +25,11 @@ public interface IDimDoor
* @param y * @param y
* @param z * @param z
*/ */
public void placeLink(World world, int x, int y, int z); public void placeLink(World world, BlockPos pos);
public Item getDoorItem(); public Item getDoorItem();
public TileEntity initDoorTE(World world, int x, int y, int z); public TileEntity initDoorTE(World world, BlockPos pos);
/** /**
* checks if any of this doors blocks are overlapping with a rift * checks if any of this doors blocks are overlapping with a rift
@ -38,6 +39,6 @@ public interface IDimDoor
* @param z * @param z
* @return * @return
*/ */
public boolean isDoorOnRift(World world, int x, int y, int z); public boolean isDoorOnRift(World world, BlockPos pos);
} }