Added Two new Config Options
This commit is contained in:
parent
5ddfc079fc
commit
fd32bbf31a
|
|
@ -12,6 +12,12 @@ public class Configs {
|
|||
|
||||
@Comment("More complex Tile Entities slow down the player more")
|
||||
public boolean heavyTiles = true;
|
||||
|
||||
@Comment("Allow all blocks to be picked up, not just Tile Entites")
|
||||
public boolean pickupAllBlocks = false;
|
||||
|
||||
@Comment("Maximum distance from where Blocks can be picked up")
|
||||
public double maxDistance = 2.5;
|
||||
}
|
||||
|
||||
public static class ForbiddenTiles
|
||||
|
|
@ -22,6 +28,8 @@ public class Configs {
|
|||
{
|
||||
"minecraft:end_portal",
|
||||
"minecraft:end_gateway",
|
||||
"minecraft:double_plant",
|
||||
"minecraft:bed",
|
||||
"animania:block_trough",
|
||||
"animania:block_invisiblock",
|
||||
"colossalchests:*",
|
||||
|
|
@ -54,6 +62,7 @@ public class Configs {
|
|||
public String[] modelOverrides = new String[]
|
||||
{
|
||||
"minecraft:lit_furnace->minecraft:furnace",
|
||||
"minecraft:bed->minecraft:bed",
|
||||
"quark:custom_chest{type:\"spruce\"}->quark:custom_chest;0",
|
||||
"quark:custom_chest{type:\"birch\"}->quark:custom_chest;1",
|
||||
"quark:custom_chest{type:\"jungle\"}->quark:custom_chest;2",
|
||||
|
|
|
|||
|
|
@ -18,13 +18,14 @@ import net.minecraftforge.event.entity.player.PlayerInteractEvent;
|
|||
import net.minecraftforge.fml.common.eventhandler.Event.Result;
|
||||
import net.minecraftforge.fml.common.eventhandler.EventPriority;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import tschipp.carryon.common.config.CarryOnConfig;
|
||||
import tschipp.carryon.common.handler.ForbiddenTileHandler;
|
||||
import tschipp.carryon.common.handler.RegistrationHandler;
|
||||
import tschipp.carryon.common.item.ItemTile;
|
||||
|
||||
public class ItemEvents
|
||||
{
|
||||
|
||||
|
||||
@SubscribeEvent(priority = EventPriority.HIGH)
|
||||
public void onBlockClick(PlayerInteractEvent.RightClickBlock event)
|
||||
{
|
||||
|
|
@ -74,7 +75,6 @@ public class ItemEvents
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
@SubscribeEvent
|
||||
public void onBlockRightClick(PlayerInteractEvent.RightClickBlock event)
|
||||
{
|
||||
|
|
@ -91,17 +91,21 @@ public class ItemEvents
|
|||
ItemStack stack = new ItemStack(RegistrationHandler.itemTile);
|
||||
|
||||
TileEntity te = world.getTileEntity(pos);
|
||||
if (te != null && (block.getBlockHardness(state, world, pos) != -1 || player.isCreative()))
|
||||
if ((CarryOnConfig.settings.pickupAllBlocks ? true : te != null) && (block.getBlockHardness(state, world, pos) != -1 || player.isCreative()))
|
||||
{
|
||||
double distance = pos.distanceSqToCenter(player.posX, player.posY + 0.5, player.posZ);
|
||||
|
||||
if (!ItemTile.isLocked(pos, world))
|
||||
if (distance < Math.pow(CarryOnConfig.settings.maxDistance, 2))
|
||||
{
|
||||
if (ItemTile.storeTileData(te, state.getActualState(world, pos), stack))
|
||||
if (!ItemTile.isLocked(pos, world))
|
||||
{
|
||||
world.removeTileEntity(pos);
|
||||
world.setBlockToAir(pos);
|
||||
player.setHeldItem(EnumHand.MAIN_HAND, stack);
|
||||
event.setUseBlock(Result.DENY);
|
||||
if (ItemTile.storeTileData(te, world, pos, state.getActualState(world, pos), stack))
|
||||
{
|
||||
world.removeTileEntity(pos);
|
||||
world.setBlockToAir(pos);
|
||||
player.setHeldItem(EnumHand.MAIN_HAND, stack);
|
||||
event.setUseBlock(Result.DENY);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@ import java.util.Arrays;
|
|||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockDirectional;
|
||||
import net.minecraft.block.BlockHorizontal;
|
||||
|
|
@ -82,17 +84,17 @@ public class ItemTile extends Item
|
|||
{
|
||||
boolean hasDirection = false;
|
||||
boolean hasAllDirection = false;
|
||||
|
||||
|
||||
Iterator<IProperty<?>> iterator = containedblock.getDefaultState().getPropertyKeys().iterator();
|
||||
while (iterator.hasNext())
|
||||
{
|
||||
IProperty<?> prop = iterator.next();
|
||||
Object[] allowedValues = prop.getAllowedValues().toArray();
|
||||
|
||||
|
||||
if (prop instanceof PropertyDirection && this.equal(allowedValues, EnumFacing.HORIZONTALS))
|
||||
hasDirection = true;
|
||||
|
||||
if(prop instanceof PropertyDirection && this.equal(allowedValues, EnumFacing.VALUES))
|
||||
|
||||
if (prop instanceof PropertyDirection && this.equal(allowedValues, EnumFacing.VALUES))
|
||||
{
|
||||
hasAllDirection = true;
|
||||
facing2 = EnumFacing.getFacingFromVector((float) vec.xCoord, (float) vec.yCoord, (float) vec.zCoord);
|
||||
|
|
@ -100,7 +102,7 @@ public class ItemTile extends Item
|
|||
|
||||
}
|
||||
|
||||
if(hasAllDirection)
|
||||
if (hasAllDirection)
|
||||
world.setBlockState(pos2, containedstate.withProperty(BlockDirectional.FACING, facing2.getOpposite()));
|
||||
else if (hasDirection)
|
||||
world.setBlockState(pos2, containedstate.withProperty(BlockHorizontal.FACING, facing2.getOpposite()));
|
||||
|
|
@ -153,16 +155,17 @@ public class ItemTile extends Item
|
|||
return false;
|
||||
}
|
||||
|
||||
public static boolean storeTileData(TileEntity tile, IBlockState state, ItemStack stack)
|
||||
public static boolean storeTileData(@Nullable TileEntity tile, World world, BlockPos pos, IBlockState state, ItemStack stack)
|
||||
{
|
||||
if (tile == null)
|
||||
if (CarryOnConfig.settings.pickupAllBlocks ? false : tile == null)
|
||||
return false;
|
||||
|
||||
if (stack.isEmpty())
|
||||
return false;
|
||||
|
||||
NBTTagCompound chest = new NBTTagCompound();
|
||||
chest = tile.writeToNBT(chest);
|
||||
if (tile != null)
|
||||
chest = tile.writeToNBT(chest);
|
||||
|
||||
NBTTagCompound tag = stack.hasTagCompound() ? stack.getTagCompound() : new NBTTagCompound();
|
||||
if (tag.hasKey(TILE_DATA_KEY))
|
||||
|
|
@ -170,8 +173,8 @@ public class ItemTile extends Item
|
|||
|
||||
tag.setTag(TILE_DATA_KEY, chest);
|
||||
|
||||
ItemStack drop = state.getBlock().getItem(tile.getWorld(), tile.getPos(), state);
|
||||
|
||||
ItemStack drop = state.getBlock().getItem(world, pos, state);
|
||||
|
||||
tag.setString("block", state.getBlock().getRegistryName().toString());
|
||||
Item item = Item.getItemFromBlock(state.getBlock());
|
||||
tag.setInteger("meta", drop.getItemDamage());
|
||||
|
|
@ -228,7 +231,7 @@ public class ItemTile extends Item
|
|||
{
|
||||
return new ItemStack(getBlock(stack), 1, getMeta(stack));
|
||||
}
|
||||
|
||||
|
||||
public static IBlockState getBlockState(ItemStack stack)
|
||||
{
|
||||
if (stack.hasTagCompound())
|
||||
|
|
@ -239,43 +242,42 @@ public class ItemTile extends Item
|
|||
}
|
||||
return Blocks.AIR.getDefaultState();
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static boolean isLocked(BlockPos pos, World world)
|
||||
{
|
||||
{
|
||||
TileEntity te = world.getTileEntity(pos);
|
||||
if(te != null)
|
||||
if (te != null)
|
||||
{
|
||||
NBTTagCompound tag = new NBTTagCompound();
|
||||
te.writeToNBT(tag);
|
||||
return tag.hasKey("Lock") ? !tag.getString("Lock").equals("") : false;
|
||||
}
|
||||
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
private boolean equal(Object[] a, Object[] b)
|
||||
{
|
||||
if (a.length != b.length)
|
||||
return false;
|
||||
|
||||
|
||||
List lA = Arrays.asList(a);
|
||||
List lB = Arrays.asList(b);
|
||||
|
||||
return lA.containsAll(lB);
|
||||
}
|
||||
|
||||
|
||||
private int potionLevel(ItemStack stack)
|
||||
{
|
||||
String nbt = getTileData(stack).toString();
|
||||
int i = nbt.length() / 500;
|
||||
|
||||
if(i > 4)
|
||||
|
||||
if (i > 4)
|
||||
i = 4;
|
||||
|
||||
if(!CarryOnConfig.settings.heavyTiles)
|
||||
|
||||
if (!CarryOnConfig.settings.heavyTiles)
|
||||
i = 1;
|
||||
|
||||
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user