Skip to content

Commit

Permalink
Fixed landmine behaviors
Browse files Browse the repository at this point in the history
- TODO: Fix sync issues in landmines
  • Loading branch information
fuj1n committed Feb 16, 2014
1 parent 20eafc2 commit ac5dcee
Show file tree
Hide file tree
Showing 5 changed files with 143 additions and 90 deletions.
3 changes: 0 additions & 3 deletions src/main/java/tconstruct/TConstruct.java
Expand Up @@ -79,9 +79,6 @@ public class TConstruct
@SidedProxy(clientSide = "tconstruct.client.TProxyClient", serverSide = "tconstruct.common.TProxyCommon")
public static TProxyCommon proxy;

//The name of the enum is accompanied by numbers because I have no idea what will happen if another mod will try to add the same enum, just to be safe
//public static EnumCreatureType creatureTypePlayer = EnumHelper.addCreatureType("PLAYER_5821443", EntityPlayer.class, 0, Material.air, true);

//The packet pipeline
public static final PacketPipeline packetPipeline = new PacketPipeline();

Expand Down
90 changes: 39 additions & 51 deletions src/main/java/tconstruct/blocks/BlockLandmine.java
@@ -1,43 +1,26 @@
package tconstruct.blocks;

import static net.minecraftforge.common.util.ForgeDirection.DOWN;
import static net.minecraftforge.common.util.ForgeDirection.EAST;
import static net.minecraftforge.common.util.ForgeDirection.NORTH;
import static net.minecraftforge.common.util.ForgeDirection.SOUTH;
import static net.minecraftforge.common.util.ForgeDirection.UP;
import static net.minecraftforge.common.util.ForgeDirection.WEST;

import java.util.Iterator;
import java.util.List;
import java.util.Random;
import static net.minecraftforge.common.util.ForgeDirection.*;

import java.util.*;
import mantle.blocks.BlockUtils;
import mantle.world.WorldHelper;
import net.minecraft.block.Block;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.*;
import net.minecraft.block.BlockPressurePlate.Sensitivity;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.item.EntityTNTPrimed;
import net.minecraft.entity.*;
import net.minecraft.entity.item.*;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.item.*;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.IIcon;
import net.minecraft.util.MathHelper;
import net.minecraft.world.Explosion;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraft.util.*;
import net.minecraft.world.*;
import net.minecraftforge.common.util.ForgeDirection;
import tconstruct.TConstruct;
import tconstruct.blocks.logic.LandmineExplodeLogic;
import tconstruct.blocks.logic.TileEntityLandmine;
import tconstruct.blocks.logic.*;
import tconstruct.client.block.RenderLandmine;
import tconstruct.common.TProxyCommon;
import tconstruct.util.landmine.Helper;
Expand All @@ -52,7 +35,6 @@ public class BlockLandmine extends BlockContainer

// Should explode when broken instead of dropping items(may not actually work
boolean explodeOnBroken = false;
private Sensitivity field_150069_a;

public BlockLandmine()
{
Expand Down Expand Up @@ -190,7 +172,7 @@ public void breakBlock (World par1World, int par2, int par3, int par4, Block par
}
}

par1World.setBlock(par2, par3, par4, par5Block);
WorldHelper.setBlockToAir(par1World, par2, par3, par4);
}
else if (explodeOnBroken)
{
Expand Down Expand Up @@ -458,15 +440,12 @@ private boolean hasItems (World par1World, int par2, int par3, int par4)
}
}

public static enum Sensitivity
{
everything, mobs, players;
}

protected int getMineState (World par1World, int par2, int par3, int par4)
{
TileEntityLandmine te = (TileEntityLandmine) par1World.getTileEntity(par2, par3, par4);

Sensitivity triggerType;

// Change to return 1 if you want the landmine to blow up when the block
// holding it is broken
if (te == null)
Expand All @@ -476,34 +455,34 @@ protected int getMineState (World par1World, int par2, int par3, int par4)
switch (te.triggerType)
{
case 0:
field_150069_a = Sensitivity.everything;
triggerType = Sensitivity.everything;
break;
case 1:
field_150069_a = Sensitivity.mobs;
triggerType = Sensitivity.mobs;
break;
case 2:
field_150069_a = Sensitivity.players;
triggerType = Sensitivity.players;
break;
default:
field_150069_a = null;
triggerType = null;
break;
}

if (field_150069_a != null)
if (triggerType != null)
{
List list = null;

if (field_150069_a == Sensitivity.everything)
if (triggerType == Sensitivity.everything)
{
list = par1World.getEntitiesWithinAABBExcludingEntity((Entity) null, getSensitiveAABB(par1World, par2, par3, par4));
}

if (field_150069_a == Sensitivity.mobs)
if (triggerType == Sensitivity.mobs)
{
list = par1World.getEntitiesWithinAABB(EntityLivingBase.class, getSensitiveAABB(par1World, par2, par3, par4));
}

if (field_150069_a == Sensitivity.players)
if (triggerType == Sensitivity.players)
{
list = par1World.getEntitiesWithinAABB(EntityPlayer.class, this.getSensitiveAABB(par1World, par2, par3, par4));
}
Expand Down Expand Up @@ -563,6 +542,8 @@ public Entity getMineTriggerer (World par1World, int par2, int par3, int par4)

TileEntityLandmine te = (TileEntityLandmine) par1World.getTileEntity(par2, par3, par4);

Sensitivity triggerType;

// Change to return 1 if you want the landmine to blow up when the
// block holding it is broken
if (te == null)
Expand All @@ -572,34 +553,34 @@ public Entity getMineTriggerer (World par1World, int par2, int par3, int par4)
switch (te.triggerType)
{
case 0:
field_150069_a = Sensitivity.everything;
triggerType = Sensitivity.everything;
break;
case 1:
field_150069_a = Sensitivity.mobs;
triggerType = Sensitivity.mobs;
break;
case 2:
field_150069_a = Sensitivity.players;
triggerType = Sensitivity.players;
break;
default:
field_150069_a = null;
triggerType = null;
break;
}

if (field_150069_a != null)
if (triggerType != null)
{
List list = null;

if (field_150069_a == Sensitivity.everything)
if (triggerType == Sensitivity.everything)
{
list = par1World.getEntitiesWithinAABBExcludingEntity((Entity) null, AxisAlignedBB.getAABBPool().getAABB(par2 + 0D, par3 + 0D, par4 + 0D, par2 + 1D, par3 + 1D, par4 + 1D));
}

if (field_150069_a == Sensitivity.mobs)
if (triggerType == Sensitivity.mobs)
{
list = par1World.getEntitiesWithinAABB(EntityLivingBase.class, AxisAlignedBB.getAABBPool().getAABB(par2 + 0D, par3 + 0D, par4 + 0D, par2 + 1D, par3 + 1D, par4 + 1D));
}

if (field_150069_a == Sensitivity.players)
if (triggerType == Sensitivity.players)
{
list = par1World.getEntitiesWithinAABB(EntityPlayer.class, AxisAlignedBB.getAABBPool().getAABB(par2 + 0D, par3 + 0D, par4 + 0D, par2 + 1D, par3 + 1D, par4 + 1D));
}
Expand Down Expand Up @@ -629,7 +610,6 @@ public boolean canDropFromExplosion (Explosion par1Explosion)
return false;
}

@SuppressWarnings("incomplete-switch")
@Override
public void setBlockBoundsBasedOnState (IBlockAccess par1IBlockAccess, int par2, int par3, int par4)
{
Expand Down Expand Up @@ -658,9 +638,17 @@ public void setBlockBoundsBasedOnState (IBlockAccess par1IBlockAccess, int par2,
case WEST:
this.setBlockBounds(0.0F, 0.0625F, 0.0625F, 0.0625F, 1.0F - 0.0625F, 1.0F - 0.0625F);
break;
default:
this.setBlockBounds(0, 0, 0, 1, 1, 1);
break;
}
}

@Override
public int damageDropped (int par1){
return par1;
}

@Override
public Item getItemDropped (int par1, Random par2Random, int par3)
{
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/tconstruct/client/gui/GuiLandmine.java
Expand Up @@ -47,7 +47,7 @@ protected void renderToolTip (ItemStack par1ItemStack, int par2, int par3)
{
if (k == 0)
{
list.set(k, "\u00a7" + Integer.toHexString(par1ItemStack.getRarity().rarityColor.getFormattingCode()) + (String) list.get(k));
list.set(k, par1ItemStack.getRarity().rarityColor + (String)list.get(k));
}
else
{
Expand Down
60 changes: 60 additions & 0 deletions src/main/java/tconstruct/util/landmine/LandmineStack.java
@@ -0,0 +1,60 @@
package tconstruct.util.landmine;

import net.minecraft.block.Block;
import net.minecraft.item.*;

public class LandmineStack {

public final boolean isBlock;
public final Block block;
public final Item item;
public final int meta;

public LandmineStack(Block block){
this(block, -314159265);
}

public LandmineStack(Item item){
this(item, -314159265);
}

public LandmineStack(Block block, int meta){
isBlock = true;
this.block = block;
this.item = null;
this.meta = meta;
}

public LandmineStack(Item item, int meta){
isBlock = false;
this.block = null;
this.item = item;
this.meta = meta;
}

@Override
public boolean equals(Object o){
//Comparing landmine stacks
if(o instanceof LandmineStack){
LandmineStack stack = (LandmineStack)o;
if(isBlock){
return block == stack.block && (meta == stack.meta || meta == -314159265);
}else{
return item == stack.item && (meta == stack.meta || meta == -314159265);
}
//Comparing landmine stacks with item stacks
}else if(o instanceof ItemStack){
ItemStack stack = (ItemStack) o;
if(isBlock && stack.getItem() instanceof ItemBlock){
return block == ((ItemBlock)stack.getItem()).field_150939_a && (meta == stack.getItemDamage() || meta == -314159265);
}else if(!isBlock){
return item == stack.getItem() && (meta == stack.getItemDamage() || meta == -314159265);
}else{
return false;
}
}else{
return false;
}
}

}

0 comments on commit ac5dcee

Please sign in to comment.