Merge branch 'master' into 1.12

This commit is contained in:
Tschipp 2017-08-14 14:54:06 +02:00
commit b1d91bf29d
3 changed files with 48 additions and 33 deletions

View File

@ -12,6 +12,12 @@ public class Configs {
@Comment("More complex Tile Entities slow down the player more") @Comment("More complex Tile Entities slow down the player more")
public boolean heavyTiles = true; 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 public static class ForbiddenTiles
@ -22,6 +28,8 @@ public class Configs {
{ {
"minecraft:end_portal", "minecraft:end_portal",
"minecraft:end_gateway", "minecraft:end_gateway",
"minecraft:double_plant",
"minecraft:bed",
"animania:block_trough", "animania:block_trough",
"animania:block_invisiblock", "animania:block_invisiblock",
"colossalchests:*", "colossalchests:*",
@ -54,6 +62,7 @@ public class Configs {
public String[] modelOverrides = new String[] public String[] modelOverrides = new String[]
{ {
"minecraft:lit_furnace->minecraft:furnace", "minecraft:lit_furnace->minecraft:furnace",
"minecraft:bed->minecraft:bed",
"quark:custom_chest{type:\"spruce\"}->quark:custom_chest;0", "quark:custom_chest{type:\"spruce\"}->quark:custom_chest;0",
"quark:custom_chest{type:\"birch\"}->quark:custom_chest;1", "quark:custom_chest{type:\"birch\"}->quark:custom_chest;1",
"quark:custom_chest{type:\"jungle\"}->quark:custom_chest;2", "quark:custom_chest{type:\"jungle\"}->quark:custom_chest;2",

View File

@ -18,6 +18,7 @@ import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import net.minecraftforge.fml.common.eventhandler.Event.Result; import net.minecraftforge.fml.common.eventhandler.Event.Result;
import net.minecraftforge.fml.common.eventhandler.EventPriority; import net.minecraftforge.fml.common.eventhandler.EventPriority;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import tschipp.carryon.common.config.CarryOnConfig;
import tschipp.carryon.common.handler.ForbiddenTileHandler; import tschipp.carryon.common.handler.ForbiddenTileHandler;
import tschipp.carryon.common.handler.RegistrationHandler; import tschipp.carryon.common.handler.RegistrationHandler;
import tschipp.carryon.common.item.ItemTile; import tschipp.carryon.common.item.ItemTile;
@ -74,7 +75,6 @@ public class ItemEvents
} }
} }
@SubscribeEvent @SubscribeEvent
public void onBlockRightClick(PlayerInteractEvent.RightClickBlock event) public void onBlockRightClick(PlayerInteractEvent.RightClickBlock event)
{ {
@ -91,17 +91,21 @@ public class ItemEvents
ItemStack stack = new ItemStack(RegistrationHandler.itemTile); ItemStack stack = new ItemStack(RegistrationHandler.itemTile);
TileEntity te = world.getTileEntity(pos); 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); if (ItemTile.storeTileData(te, world, pos, state.getActualState(world, pos), stack))
world.setBlockToAir(pos); {
player.setHeldItem(EnumHand.MAIN_HAND, stack); world.removeTileEntity(pos);
event.setUseBlock(Result.DENY); world.setBlockToAir(pos);
player.setHeldItem(EnumHand.MAIN_HAND, stack);
event.setUseBlock(Result.DENY);
}
} }
} }

View File

@ -4,6 +4,8 @@ import java.util.Arrays;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import javax.annotation.Nullable;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.BlockDirectional; import net.minecraft.block.BlockDirectional;
import net.minecraft.block.BlockHorizontal; import net.minecraft.block.BlockHorizontal;
@ -93,7 +95,7 @@ public class ItemTile extends Item
if (prop instanceof PropertyDirection && this.equal(allowedValues, EnumFacing.HORIZONTALS)) if (prop instanceof PropertyDirection && this.equal(allowedValues, EnumFacing.HORIZONTALS))
hasDirection = true; hasDirection = true;
if(prop instanceof PropertyDirection && this.equal(allowedValues, EnumFacing.VALUES)) if (prop instanceof PropertyDirection && this.equal(allowedValues, EnumFacing.VALUES))
{ {
hasAllDirection = true; hasAllDirection = true;
facing2 = EnumFacing.getFacingFromVector((float) vec.x, (float) vec.y, (float) vec.z); facing2 = EnumFacing.getFacingFromVector((float) vec.x, (float) vec.y, (float) vec.z);
@ -101,7 +103,7 @@ public class ItemTile extends Item
} }
if(hasAllDirection) if (hasAllDirection)
world.setBlockState(pos2, containedstate.withProperty(BlockDirectional.FACING, facing2.getOpposite())); world.setBlockState(pos2, containedstate.withProperty(BlockDirectional.FACING, facing2.getOpposite()));
else if (hasDirection) else if (hasDirection)
world.setBlockState(pos2, containedstate.withProperty(BlockHorizontal.FACING, facing2.getOpposite())); world.setBlockState(pos2, containedstate.withProperty(BlockHorizontal.FACING, facing2.getOpposite()));
@ -154,16 +156,17 @@ public class ItemTile extends Item
return false; 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; return false;
if (stack.isEmpty()) if (stack.isEmpty())
return false; return false;
NBTTagCompound chest = new NBTTagCompound(); NBTTagCompound chest = new NBTTagCompound();
chest = tile.writeToNBT(chest); if (tile != null)
chest = tile.writeToNBT(chest);
NBTTagCompound tag = stack.hasTagCompound() ? stack.getTagCompound() : new NBTTagCompound(); NBTTagCompound tag = stack.hasTagCompound() ? stack.getTagCompound() : new NBTTagCompound();
if (tag.hasKey(TILE_DATA_KEY)) if (tag.hasKey(TILE_DATA_KEY))
@ -171,7 +174,7 @@ public class ItemTile extends Item
tag.setTag(TILE_DATA_KEY, chest); 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()); tag.setString("block", state.getBlock().getRegistryName().toString());
Item item = Item.getItemFromBlock(state.getBlock()); Item item = Item.getItemFromBlock(state.getBlock());
@ -241,18 +244,17 @@ public class ItemTile extends Item
return Blocks.AIR.getDefaultState(); return Blocks.AIR.getDefaultState();
} }
public static boolean isLocked(BlockPos pos, World world) public static boolean isLocked(BlockPos pos, World world)
{ {
TileEntity te = world.getTileEntity(pos); TileEntity te = world.getTileEntity(pos);
if(te != null) if (te != null)
{ {
NBTTagCompound tag = new NBTTagCompound(); NBTTagCompound tag = new NBTTagCompound();
te.writeToNBT(tag); te.writeToNBT(tag);
return tag.hasKey("Lock") ? !tag.getString("Lock").equals("") : false; return tag.hasKey("Lock") ? !tag.getString("Lock").equals("") : false;
} }
return true; return false;
} }
private boolean equal(Object[] a, Object[] b) private boolean equal(Object[] a, Object[] b)
@ -271,10 +273,10 @@ public class ItemTile extends Item
String nbt = getTileData(stack).toString(); String nbt = getTileData(stack).toString();
int i = nbt.length() / 500; int i = nbt.length() / 500;
if(i > 4) if (i > 4)
i = 4; i = 4;
if(!CarryOnConfig.settings.heavyTiles) if (!CarryOnConfig.settings.heavyTiles)
i = 1; i = 1;
return i; return i;