Finished BaseDimDoor.

This commit is contained in:
zangamj 2016-06-21 20:59:56 -04:00
parent fbd6cb2d13
commit 1b87445f8a
4 changed files with 81 additions and 162 deletions

View file

@ -3,8 +3,13 @@ package com.zixiken.dimdoors.blocks;
import java.util.Random; import java.util.Random;
import com.zixiken.dimdoors.DimDoors; import com.zixiken.dimdoors.DimDoors;
import com.zixiken.dimdoors.core.LinkType;
import com.zixiken.dimdoors.core.DimLink; import com.zixiken.dimdoors.core.DimLink;
import com.zixiken.dimdoors.core.DDTeleporter;
import com.zixiken.dimdoors.core.LinkType;
import com.zixiken.dimdoors.core.PocketManager;
import com.zixiken.dimdoors.items.ItemDDKey;
import com.zixiken.dimdoors.tileentities.TileEntityDimDoor;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.BlockDoor; import net.minecraft.block.BlockDoor;
import net.minecraft.block.ITileEntityProvider; import net.minecraft.block.ITileEntityProvider;
@ -18,14 +23,9 @@ 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.EnumFacing;
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;
import net.minecraft.world.World; import net.minecraft.world.World;
import com.zixiken.dimdoors.core.DDTeleporter;
import com.zixiken.dimdoors.core.PocketManager;
import com.zixiken.dimdoors.items.ItemDDKey;
import com.zixiken.dimdoors.tileentities.TileEntityDimDoor;
import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly; import net.minecraftforge.fml.relauncher.SideOnly;
@ -111,29 +111,25 @@ public abstract class BaseDimDoor extends BlockDoor implements IDimDoor, ITileEn
return null; return null;
} }
/**
* Is this block (a) opaque and (b) a full 1m cube? This determines whether or not to render the shared face of two
* adjacent blocks and also whether the player can attach torches, redstone wire, etc to this block.
*/
@Override @Override
public void updateTick(World par1World, BlockPos pos, IBlockState state, Random rand) { public void updateTick(World par1World, BlockPos pos, IBlockState state, Random rand) {
this.updateAttachedTile(par1World, pos); updateAttachedTile(par1World, pos);
} }
@Override @Override
public void setBlockBoundsBasedOnState(IBlockAccess par1IBlockAccess, int par2, int par3, int par4) public void setBlockBoundsBasedOnState(IBlockAccess worldIn, BlockPos pos)
{ {
this.setDoorRotation(func_150012_g(par1IBlockAccess, par2, par3, par4)); this.setDoorRotation(worldIn.getBlockState(pos));
} }
public void setDoorRotation(int par1) private void setDoorRotation(IBlockState state)
{ {
float var2 = 0.1875F; float var2 = 0.1875F;
this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 2.0F, 1.0F); setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 2.0F, 1.0F);
int var3 = par1 & 3; int var3 = state.getValue(BlockDoor.FACING).rotateY().getHorizontalIndex();
boolean var4 = (par1 & 4) != 0; boolean var4 = state.getValue(BlockDoor.OPEN);
boolean var5 = (par1 & 16) != 0; boolean var5 = state.getValue(BlockDoor.HINGE) == EnumHingePosition.LEFT;
if (var3 == 0) if (var3 == 0)
{ {
@ -141,16 +137,16 @@ public abstract class BaseDimDoor extends BlockDoor implements IDimDoor, ITileEn
{ {
if (!var5) if (!var5)
{ {
this.setBlockBounds(0.001F, 0.0F, 0.0F, 1.0F, 1.0F, var2); setBlockBounds(0.001F, 0.0F, 0.0F, 1.0F, 1.0F, var2);
} }
else else
{ {
this.setBlockBounds(0.001F, 0.0F, 1.0F - var2, 1.0F, 1.0F, 1.0F); setBlockBounds(0.001F, 0.0F, 1.0F - var2, 1.0F, 1.0F, 1.0F);
} }
} }
else else
{ {
this.setBlockBounds(0.0F, 0.0F, 0.0F, var2, 1.0F, 1.0F); setBlockBounds(0.0F, 0.0F, 0.0F, var2, 1.0F, 1.0F);
} }
} }
else if (var3 == 1) else if (var3 == 1)
@ -159,16 +155,16 @@ public abstract class BaseDimDoor extends BlockDoor implements IDimDoor, ITileEn
{ {
if (!var5) if (!var5)
{ {
this.setBlockBounds(1.0F - var2, 0.0F, 0.001F, 1.0F, 1.0F, 1.0F); setBlockBounds(1.0F - var2, 0.0F, 0.001F, 1.0F, 1.0F, 1.0F);
} }
else else
{ {
this.setBlockBounds(0.0F, 0.0F, 0.001F, var2, 1.0F, 1.0F); setBlockBounds(0.0F, 0.0F, 0.001F, var2, 1.0F, 1.0F);
} }
} }
else else
{ {
this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, var2); setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, var2);
} }
} }
else if (var3 == 2) else if (var3 == 2)
@ -177,16 +173,16 @@ public abstract class BaseDimDoor extends BlockDoor implements IDimDoor, ITileEn
{ {
if (!var5) if (!var5)
{ {
this.setBlockBounds(0.0F, 0.0F, 1.0F - var2, .99F, 1.0F, 1.0F); setBlockBounds(0.0F, 0.0F, 1.0F - var2, .99F, 1.0F, 1.0F);
} }
else else
{ {
this.setBlockBounds(0.0F, 0.0F, 0.0F, .99F, 1.0F, var2); setBlockBounds(0.0F, 0.0F, 0.0F, .99F, 1.0F, var2);
} }
} }
else else
{ {
this.setBlockBounds(1.0F - var2, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F); setBlockBounds(1.0F - var2, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
} }
} }
else if (var3 == 3) else if (var3 == 3)
@ -195,16 +191,16 @@ public abstract class BaseDimDoor extends BlockDoor implements IDimDoor, ITileEn
{ {
if (!var5) if (!var5)
{ {
this.setBlockBounds(0.0F, 0.0F, 0.0F, var2, 1.0F, 0.99F); setBlockBounds(0.0F, 0.0F, 0.0F, var2, 1.0F, 0.99F);
} }
else else
{ {
this.setBlockBounds(1.0F - var2, 0.0F, 0.0F, 1.0F, 1.0F, 0.99F); setBlockBounds(1.0F - var2, 0.0F, 0.0F, 1.0F, 1.0F, 0.99F);
} }
} }
else else
{ {
this.setBlockBounds(0.0F, 0.0F, 1.0F - var2, 1.0F, 1.0F, 1.0F); setBlockBounds(0.0F, 0.0F, 1.0F - var2, 1.0F, 1.0F, 1.0F);
} }
} }
} }
@ -217,28 +213,20 @@ public abstract class BaseDimDoor extends BlockDoor implements IDimDoor, ITileEn
@Override @Override
public void onNeighborBlockChange(World world, BlockPos pos, IBlockState state, Block neighbor) { public void onNeighborBlockChange(World world, BlockPos pos, IBlockState state, Block neighbor) {
int metadata = getMetaFromState(world.getBlockState(pos));
if (isUpperDoorBlock(state)) { if (isUpperDoorBlock(state)) {
if (world.getBlockState(pos.down()) != this) { if (world.getBlockState(pos.down()) != this)
world.setBlockToAir(pos); world.setBlockToAir(pos);
} if (!neighbor.isAir(world, pos) && neighbor != this)
if (!neighbor.isAir(world, pos) && neighbor != this) { onNeighborBlockChange(world, pos.down(), state, neighbor);
this.onNeighborBlockChange(world, pos.down(), state, neighbor); } else {
}
}
else {
if (world.getBlockState(pos.up()) != this) { if (world.getBlockState(pos.up()) != this) {
world.setBlockToAir(pos); world.setBlockToAir(pos);
if (!world.isRemote) { if (!world.isRemote) dropBlockAsItem(world, pos, state, 0);
this.dropBlockAsItem(world, pos, state, 0);
}
} }
else if(this.getLockStatus(world, pos)<=1) { else if(this.getLockStatus(world, pos)<=1) {
boolean powered = world.isBlockPowered(pos) || world.isBlockPowered(pos.up()); boolean powered = world.isBlockPowered(pos) || world.isBlockPowered(pos.up());
if ((powered || !neighbor.isAir(world, pos) && neighbor.canProvidePower()) && neighbor != this) if ((powered || !neighbor.isAir(world, pos) && neighbor.canProvidePower()) && neighbor != this)
{ toggleDoor(world, pos, powered);
this.toggleDoor(world, pos, powered);
}
} }
} }
} }
@ -262,44 +250,30 @@ public abstract class BaseDimDoor extends BlockDoor implements IDimDoor, ITileEn
@Override @Override
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
public Item getItem(World world, BlockPos pos) { public Item getItem(World world, BlockPos pos) {return this.getDoorItem();}
return this.getDoorItem();
}
@Override @Override
public TileEntity createNewTileEntity(World world, int metadata) public TileEntity createNewTileEntity(World world, int metadata) {return new TileEntityDimDoor();}
{
return new TileEntityDimDoor();
}
@Override @Override
public void enterDimDoor(World world, BlockPos pos, 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) {return;}
return;
}
// Check that this is the top block of the door // Check that this is the top block of the door
if (world.getBlock(x, y - 1, z) == this) { if (world.getBlockState(pos).getValue(BlockDoor.HALF) == EnumDoorHalf.UPPER) {
int metadata = world.getBlockMetadata(x, y - 1, z); IBlockState state = world.getBlockState(pos.down());
boolean canUse = isDoorOpen(metadata); boolean canUse = state.getValue(BlockDoor.OPEN);
if (canUse && entity instanceof EntityPlayer) if (canUse && entity instanceof EntityPlayer)
{
// Dont check for non-player entites // Dont check for non-player entites
canUse = isEntityFacingDoor(metadata, (EntityLivingBase) entity); canUse = isEntityFacingDoor(state, (EntityLivingBase) entity);
} if (canUse) {
if (canUse)
{
// Teleport the entity through the link, if it exists // Teleport the entity through the link, if it exists
DimLink link = PocketManager.getLink(x, y, z, world.provider.dimensionId); DimLink link = PocketManager.getLink(pos, world.provider.getDimensionId());
if (link != null && (link.linkType() != LinkType.PERSONAL || entity instanceof EntityPlayer)) if (link != null && (link.linkType() != LinkType.PERSONAL || entity instanceof EntityPlayer)) {
{ try {
try
{
DDTeleporter.traverseDimDoor(world, link, entity, this); DDTeleporter.traverseDimDoor(world, link, entity, this);
} } catch (IllegalArgumentException e) {
catch (Exception e)
{
System.err.println("Something went wrong teleporting to a dimension:"); System.err.println("Something went wrong teleporting to a dimension:");
e.printStackTrace(); e.printStackTrace();
} }
@ -307,24 +281,15 @@ public abstract class BaseDimDoor extends BlockDoor implements IDimDoor, ITileEn
// Close the door only after the entity goes through // Close the door only after the entity goes through
// so players don't have it slam in their faces. // so players don't have it slam in their faces.
this.func_150014_a(world, x, y, z, false); this.toggleDoor(world, pos, false);
} }
} } else {
else if (world.getBlock(x, y + 1, z) == this) BlockPos up = pos.up();
{ if (world.getBlockState(up).getBlock() == this) enterDimDoor(world, up, entity);
enterDimDoor(world, x, y + 1, z, entity);
} }
} }
public boolean isUpperDoorBlock(IBlockState state) public boolean isUpperDoorBlock(IBlockState state) {return state.getValue(BlockDoor.HALF) == EnumDoorHalf.UPPER;}
{
return state.getValue(BlockDoor.HALF) == EnumDoorHalf.UPPER;
}
public boolean isDoorOpen(int metadata)
{
return (metadata & 4) != 0;
}
/** /**
* 0 if link is no lock; * 0 if link is no lock;
@ -334,84 +299,51 @@ public abstract class BaseDimDoor extends BlockDoor implements IDimDoor, ITileEn
* @param pos * @param pos
* @return * @return
*/ */
public byte getLockStatus(World world, BlockPos pos) public byte getLockStatus(World world, BlockPos pos) {
{
byte status = 0; byte status = 0;
DimLink link = getLink(world, pos); DimLink link = getLink(world, pos);
if(link!=null&&link.hasLock()) if(link != null && link.hasLock()) {
{
status++; status++;
if(link.getLockState()) if(link.getLockState()) status++;
{
status++;
}
} }
return status; return status;
} }
public boolean checkCanOpen(World world, BlockPos pos, EntityPlayer player) {
public boolean checkCanOpen(World world, BlockPos pos)
{
return this.checkCanOpen(world, pos, null);
}
public boolean checkCanOpen(World world, BlockPos pos, EntityPlayer player)
{
DimLink link = getLink(world, pos); DimLink link = getLink(world, pos);
if(link==null||player==null) if(link == null || player == null) return link == null;
{ if(!link.getLockState()) return true;
return link==null;
}
if(!link.getLockState())
{
return true;
}
for(ItemStack item : player.inventory.mainInventory) for(ItemStack item : player.inventory.mainInventory)
{ if(item != null && item.getItem() instanceof ItemDDKey && link.tryToOpen(item)) return true;
if(item != null)
{
if(item.getItem() instanceof ItemDDKey)
{
if(link.tryToOpen(item))
{
return true;
}
}
}
}
player.playSound(DimDoors.MODID + ":doorLocked", 1F, 1F); player.playSound(DimDoors.MODID + ":doorLocked", 1F, 1F);
return false; return false;
} }
protected static boolean isEntityFacingDoor(int metadata, EntityLivingBase entity) protected static boolean isEntityFacingDoor(IBlockState state, EntityLivingBase entity) {
{
// Although any entity has the proper fields for this check, // Although any entity has the proper fields for this check,
// we should only apply it to living entities since things // we should only apply it to living entities since things
// like Minecarts might come in backwards. // like Minecarts might come in backwards.
int direction = MathHelper.floor_double((entity.rotationYaw + 90) * 4.0F / 360.0F + 0.5D) & 3; return (state.getValue(BlockDoor.FACING) == EnumFacing.fromAngle(entity.rotationYaw));
return ((metadata & 3) == direction);
} }
@Override @Override
public TileEntity initDoorTE(World world, BlockPos pos) { public TileEntity initDoorTE(World world, BlockPos pos) {
TileEntity te = this.createTileEntity(world, world.getBlockState(pos)); TileEntity te = createTileEntity(world, world.getBlockState(pos));
world.setTileEntity(pos, te); world.setTileEntity(pos, te);
return te; return te;
} }
@Override @Override
public void breakBlock(World world, BlockPos pos, IBlockState state) public void breakBlock(World world, BlockPos pos, IBlockState state) {
{
// This function runs on the server side after a block is replaced // This function runs on the server side after a block is replaced
// We MUST call super.breakBlock() since it involves removing tile entities // We MUST call super.breakBlock() since it involves removing tile entities
super.breakBlock(world, pos, state); super.breakBlock(world, pos, state);
// Schedule rift regeneration for this block if it was replaced // Schedule rift regeneration for this block if it was replaced
if (world.getBlock(x, y, z) != oldBlock) if (world.getBlockState(pos).getBlock() != state.getBlock())
{ DimDoors.riftRegenerator.scheduleFastRegeneration(pos, world);
DimDoors.riftRegenerator.scheduleFastRegeneration(x, y, z, world);
}
} }
} }

View file

@ -401,24 +401,12 @@ public class DDTeleporter
* @param link - the link the player is using to teleport; sends the player to its destination * @param link - the link the player is using to teleport; sends the player to its destination
* @param entity - the instance of the player to be teleported * @param entity - the instance of the player to be teleported
*/ */
public static void traverseDimDoor(World world, DimLink link, Entity entity, Block door) public static void traverseDimDoor(World world, DimLink link,
{ Entity entity, Block door) throws IllegalArgumentException {
if (world == null) if(world.isRemote) return;
{ if(world == null) throw new IllegalArgumentException("world cannot be null.");
throw new IllegalArgumentException("world cannot be null."); if(link == null) throw new IllegalArgumentException("link cannot be null.");
} if(entity == null) throw new IllegalArgumentException("entity cannot be null.");
if (link == null)
{
throw new IllegalArgumentException("link cannot be null.");
}
if (entity == null)
{
throw new IllegalArgumentException("entity cannot be null.");
}
if (world.isRemote)
{
return;
}
if (cooldown == 0 || entity instanceof EntityPlayer) if (cooldown == 0 || entity instanceof EntityPlayer)
{ {

View file

@ -656,9 +656,9 @@ public class PocketManager
isConnected = false; isConnected = false;
} }
public static DimLink getLink(int x, int y, int z, World world) public static DimLink getLink(BlockPos pos, World world)
{ {
return getLink(x, y, z, world.provider.getDimensionId()); return getLink(pos, world.provider.getDimensionId());
} }
public static DimLink getLink(Point4D point) public static DimLink getLink(Point4D point)

View file

@ -6,6 +6,7 @@ import java.util.Random;
import com.zixiken.dimdoors.core.DimLink; import com.zixiken.dimdoors.core.DimLink;
import com.zixiken.dimdoors.core.PocketManager; import com.zixiken.dimdoors.core.PocketManager;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.util.BlockPos;
import net.minecraft.util.MathHelper; import net.minecraft.util.MathHelper;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.common.DimensionManager; import net.minecraftforge.common.DimensionManager;
@ -49,14 +50,12 @@ public class RiftRegenerator implements IRegularTickReceiver {
scheduleRegeneration(link, MIN_SLOW_DELAY, MAX_SLOW_DELAY); scheduleRegeneration(link, MIN_SLOW_DELAY, MAX_SLOW_DELAY);
} }
public void scheduleSlowRegeneration(int x, int y, int z, World world) public void scheduleSlowRegeneration(BlockPos pos, World world) {
{ scheduleRegeneration(PocketManager.getLink(pos, world), MIN_SLOW_DELAY, MAX_SLOW_DELAY);
scheduleRegeneration(PocketManager.getLink(x, y, z, world), MIN_SLOW_DELAY, MAX_SLOW_DELAY);
} }
public void scheduleFastRegeneration(int x, int y, int z, World world) public void scheduleFastRegeneration(BlockPos pos, World world) {
{ scheduleRegeneration(PocketManager.getLink(pos, world), MIN_FAST_DELAY, MAX_FAST_DELAY);
scheduleRegeneration(PocketManager.getLink(x, y, z, world), MIN_FAST_DELAY, MAX_FAST_DELAY);
} }
private void scheduleRegeneration(DimLink link, int minDelay, int maxDelay) private void scheduleRegeneration(DimLink link, int minDelay, int maxDelay)