mirror of
https://github.com/GTNewHorizons/TinkersConstruct.git
synced 2026-11-19 19:59:55 +00:00
Fixed landmine behaviors
- TODO: Fix sync issues in landmines
This commit is contained in:
1 parent
20eafc2cd6
commit
ac5dcee2db
5 files changed
+143
-90
No files matched your search
@@ -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();
|
||||
|
||||
|
||||
@@ -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;
|
||||
@@ -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()
|
||||
{
|
||||
@@ -190,7 +172,7 @@ public class BlockLandmine extends BlockContainer
|
||||
}
|
||||
}
|
||||
|
||||
par1World.setBlock(par2, par3, par4, par5Block);
|
||||
WorldHelper.setBlockToAir(par1World, par2, par3, par4);
|
||||
}
|
||||
else if (explodeOnBroken)
|
||||
{
|
||||
@@ -458,15 +440,12 @@ public class BlockLandmine extends BlockContainer
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
@@ -476,34 +455,34 @@ public class BlockLandmine extends BlockContainer
|
||||
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));
|
||||
}
|
||||
@@ -563,6 +542,8 @@ public class BlockLandmine extends BlockContainer
|
||||
|
||||
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)
|
||||
@@ -572,34 +553,34 @@ public class BlockLandmine extends BlockContainer
|
||||
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));
|
||||
}
|
||||
@@ -629,7 +610,6 @@ public class BlockLandmine extends BlockContainer
|
||||
return false;
|
||||
}
|
||||
|
||||
@SuppressWarnings("incomplete-switch")
|
||||
@Override
|
||||
public void setBlockBoundsBasedOnState (IBlockAccess par1IBlockAccess, int par2, int par3, int par4)
|
||||
{
|
||||
@@ -658,9 +638,17 @@ public class BlockLandmine extends BlockContainer
|
||||
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)
|
||||
{
|
||||
|
||||
@@ -47,7 +47,7 @@ public class GuiLandmine extends GuiContainer
|
||||
{
|
||||
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
|
||||
{
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,21 +1,16 @@
|
||||
package tconstruct.util.landmine.behavior;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import tconstruct.util.landmine.LandmineStack;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.ITileEntityProvider;
|
||||
import java.util.*;
|
||||
import net.minecraft.block.*;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.ItemBlock;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.init.*;
|
||||
import net.minecraft.item.*;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import tconstruct.util.landmine.Helper;
|
||||
import tconstruct.util.landmine.*;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -25,8 +20,8 @@ import tconstruct.util.landmine.Helper;
|
||||
public abstract class Behavior
|
||||
{
|
||||
|
||||
public static HashMap<ItemStack, Behavior> behaviorsListItems = new HashMap<ItemStack, Behavior>();
|
||||
public static HashMap<ItemStack, Behavior> behaviorsListBlocks = new HashMap<ItemStack, Behavior>();
|
||||
public static HashMap<LandmineStack, Behavior> behaviorsListItems = new HashMap<LandmineStack, Behavior>();
|
||||
public static HashMap<LandmineStack, Behavior> behaviorsListBlocks = new HashMap<LandmineStack, Behavior>();
|
||||
protected static Behavior defaultBehavior;
|
||||
|
||||
public static Behavior dummy = new BehaviorDummy();
|
||||
@@ -42,21 +37,22 @@ public abstract class Behavior
|
||||
|
||||
public static void registerBuiltInBehaviors ()
|
||||
{
|
||||
System.out.println("Test");
|
||||
defaultBehavior = new BehaviorDefault();
|
||||
|
||||
addBehavior(new ItemStack(Items.stick), dummy);
|
||||
addBehavior(new ItemStack(Items.redstone), utilityMode);
|
||||
addBehavior(new ItemStack(Blocks.torch), blockThrow);
|
||||
addBehavior(new ItemStack(Items.gunpowder), explosive);
|
||||
addBehavior(new ItemStack(Blocks.tnt), explosive);
|
||||
addBehavior(new ItemStack(Items.fireworks), firework);
|
||||
addBehavior(new ItemStack(Items.potionitem), potion);
|
||||
addBehavior(new ItemStack(Items.fire_charge), fireball);
|
||||
addBehavior(new ItemStack(Items.spawn_egg), spawn);
|
||||
addBehavior(new ItemStack(Items.arrow), shoot);
|
||||
addBehavior(new ItemStack(Items.snowball), shoot);
|
||||
addBehavior(new ItemStack(Items.ender_pearl), shoot);
|
||||
addBehavior(new ItemStack(Items.shears), shear);
|
||||
addBehavior(new LandmineStack(Items.stick), dummy);
|
||||
addBehavior(new LandmineStack(Items.redstone), utilityMode);
|
||||
addBehavior(new LandmineStack(Blocks.torch), blockThrow);
|
||||
addBehavior(new LandmineStack(Items.gunpowder), explosive);
|
||||
addBehavior(new LandmineStack(Blocks.tnt), explosive);
|
||||
addBehavior(new LandmineStack(Items.fireworks), firework);
|
||||
addBehavior(new LandmineStack(Items.potionitem), potion);
|
||||
addBehavior(new LandmineStack(Items.fire_charge), fireball);
|
||||
addBehavior(new LandmineStack(Items.spawn_egg), spawn);
|
||||
addBehavior(new LandmineStack(Items.arrow), shoot);
|
||||
addBehavior(new LandmineStack(Items.snowball), shoot);
|
||||
addBehavior(new LandmineStack(Items.ender_pearl), shoot);
|
||||
addBehavior(new LandmineStack(Items.shears), shear);
|
||||
|
||||
//Make sure the part below this comment is executed last(to avoid conflicts)
|
||||
Iterator i1 = Block.blockRegistry.iterator();
|
||||
@@ -68,7 +64,7 @@ public abstract class Behavior
|
||||
Block b = (Block) ob;
|
||||
if (b.getMaterial().isOpaque() && b.renderAsNormalBlock() && !b.canProvidePower() && !(b instanceof ITileEntityProvider) && !behaviorsListBlocks.containsKey(new ItemStack(b)))
|
||||
{
|
||||
addBehavior(new ItemStack(b), blockThrow);
|
||||
addBehavior(new LandmineStack(b), blockThrow);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -85,7 +81,13 @@ public abstract class Behavior
|
||||
{
|
||||
if (!behaviorsListBlocks.isEmpty())
|
||||
{
|
||||
return behaviorsListBlocks.get(par1ItemStack);
|
||||
for(int i = 0; i < behaviorsListBlocks.size(); i++){
|
||||
LandmineStack st = (LandmineStack) behaviorsListBlocks.keySet().toArray()[i];
|
||||
if(st.equals(par1ItemStack)){
|
||||
return (Behavior) behaviorsListBlocks.values().toArray()[i];
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -96,7 +98,13 @@ public abstract class Behavior
|
||||
{
|
||||
if (!behaviorsListItems.isEmpty())
|
||||
{
|
||||
return behaviorsListItems.get(par1ItemStack);
|
||||
for(int i = 0; i < behaviorsListItems.size(); i++){
|
||||
LandmineStack st = (LandmineStack) behaviorsListItems.keySet().toArray()[i];
|
||||
if(st.equals(par1ItemStack)){
|
||||
return (Behavior) behaviorsListItems.values().toArray()[i];
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -110,20 +118,20 @@ public abstract class Behavior
|
||||
return defaultBehavior;
|
||||
}
|
||||
|
||||
public static void addBehavior (ItemStack par1ItemStack, Behavior par2Behavior)
|
||||
public static void addBehavior (LandmineStack par1LandmineStack, Behavior par2Behavior)
|
||||
{
|
||||
if (par1ItemStack.getItem() instanceof ItemBlock)
|
||||
if (par1LandmineStack.isBlock)
|
||||
{
|
||||
if (!behaviorsListBlocks.containsKey(par1ItemStack))
|
||||
if (!behaviorsListBlocks.containsKey(par1LandmineStack))
|
||||
{
|
||||
behaviorsListBlocks.put(par1ItemStack, par2Behavior);
|
||||
behaviorsListBlocks.put(par1LandmineStack, par2Behavior);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!behaviorsListItems.containsKey(par1ItemStack))
|
||||
if (!behaviorsListItems.containsKey(par1LandmineStack))
|
||||
{
|
||||
behaviorsListItems.put(par1ItemStack, par2Behavior);
|
||||
behaviorsListItems.put(par1LandmineStack, par2Behavior);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user