Updated wrenching logic. Some work for #1543
This commit is contained in:
parent
baacc67a64
commit
e2225b06d4
4 changed files with 242 additions and 272 deletions
|
@ -24,13 +24,28 @@
|
||||||
|
|
||||||
package techreborn.blocks.generator;
|
package techreborn.blocks.generator;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import net.minecraft.block.material.Material;
|
import net.minecraft.block.material.Material;
|
||||||
|
import net.minecraft.block.state.IBlockState;
|
||||||
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
|
import net.minecraft.util.EnumFacing;
|
||||||
|
import net.minecraft.util.EnumHand;
|
||||||
|
import net.minecraft.util.NonNullList;
|
||||||
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
import net.minecraft.world.IBlockAccess;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import prospector.shootingstar.ShootingStar;
|
import prospector.shootingstar.ShootingStar;
|
||||||
import prospector.shootingstar.model.ModelCompound;
|
import prospector.shootingstar.model.ModelCompound;
|
||||||
|
import reborncore.api.ToolManager;
|
||||||
import reborncore.common.BaseTileBlock;
|
import reborncore.common.BaseTileBlock;
|
||||||
|
import reborncore.common.RebornCoreConfig;
|
||||||
|
import reborncore.common.blocks.BlockWrenchEventHandler;
|
||||||
|
import reborncore.common.items.WrenchHelper;
|
||||||
import techreborn.client.TechRebornCreativeTab;
|
import techreborn.client.TechRebornCreativeTab;
|
||||||
|
import techreborn.init.ModBlocks;
|
||||||
import techreborn.lib.ModInfo;
|
import techreborn.lib.ModInfo;
|
||||||
import techreborn.tiles.generator.TileCreativeSolarPanel;
|
import techreborn.tiles.generator.TileCreativeSolarPanel;
|
||||||
|
|
||||||
|
@ -44,6 +59,41 @@ public class BlockCreativeSolarPanel extends BaseTileBlock {
|
||||||
setCreativeTab(TechRebornCreativeTab.instance);
|
setCreativeTab(TechRebornCreativeTab.instance);
|
||||||
setHardness(2.0F);
|
setHardness(2.0F);
|
||||||
ShootingStar.registerModel(new ModelCompound(ModInfo.MOD_ID, this, "machines/generators"));
|
ShootingStar.registerModel(new ModelCompound(ModInfo.MOD_ID, this, "machines/generators"));
|
||||||
|
BlockWrenchEventHandler.wrenableBlocks.add(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand,
|
||||||
|
EnumFacing side, float hitX, float hitY, float hitZ) {
|
||||||
|
ItemStack stack = playerIn.getHeldItem(EnumHand.MAIN_HAND);
|
||||||
|
TileEntity tileEntity = worldIn.getTileEntity(pos);
|
||||||
|
|
||||||
|
// We extended BaseTileBlock. Thus we should always have tile entity. I hope.
|
||||||
|
if (tileEntity == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!stack.isEmpty() && ToolManager.INSTANCE.canHandleTool(stack)) {
|
||||||
|
if (WrenchHelper.handleWrench(stack, worldIn, pos, playerIn, side)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return super.onBlockActivated(worldIn, pos, state, playerIn, hand, side, hitX, hitY, hitZ);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<ItemStack> getDrops(IBlockAccess world, BlockPos pos, IBlockState state, int fortune) {
|
||||||
|
NonNullList<ItemStack> items = NonNullList.create();
|
||||||
|
|
||||||
|
if (RebornCoreConfig.wrenchRequired){
|
||||||
|
items.add(new ItemStack(ModBlocks.MACHINE_FRAMES, 1, 1));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
super.getDrops(items, world, pos, state, fortune);
|
||||||
|
}
|
||||||
|
|
||||||
|
return items;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -24,12 +24,12 @@
|
||||||
|
|
||||||
package techreborn.blocks.generator;
|
package techreborn.blocks.generator;
|
||||||
|
|
||||||
import net.minecraft.block.material.Material;
|
|
||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import prospector.shootingstar.ShootingStar;
|
import prospector.shootingstar.ShootingStar;
|
||||||
import prospector.shootingstar.model.ModelCompound;
|
import prospector.shootingstar.model.ModelCompound;
|
||||||
import reborncore.common.BaseTileBlock;
|
import reborncore.api.tile.IMachineGuiHandler;
|
||||||
|
import reborncore.common.blocks.BlockMachineBase;
|
||||||
import techreborn.client.TechRebornCreativeTab;
|
import techreborn.client.TechRebornCreativeTab;
|
||||||
import techreborn.lib.ModInfo;
|
import techreborn.lib.ModInfo;
|
||||||
import techreborn.tiles.generator.TileWaterMill;
|
import techreborn.tiles.generator.TileWaterMill;
|
||||||
|
@ -37,12 +37,11 @@ import techreborn.tiles.generator.TileWaterMill;
|
||||||
/**
|
/**
|
||||||
* Created by modmuss50 on 25/02/2016.
|
* Created by modmuss50 on 25/02/2016.
|
||||||
*/
|
*/
|
||||||
public class BlockWaterMill extends BaseTileBlock {
|
public class BlockWaterMill extends BlockMachineBase {
|
||||||
|
|
||||||
public BlockWaterMill() {
|
public BlockWaterMill() {
|
||||||
super(Material.IRON);
|
super(false);
|
||||||
setCreativeTab(TechRebornCreativeTab.instance);
|
setCreativeTab(TechRebornCreativeTab.instance);
|
||||||
setHardness(2.0F);
|
|
||||||
ShootingStar.registerModel(new ModelCompound(ModInfo.MOD_ID, this, "machines/generators"));
|
ShootingStar.registerModel(new ModelCompound(ModInfo.MOD_ID, this, "machines/generators"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,4 +49,9 @@ public class BlockWaterMill extends BaseTileBlock {
|
||||||
public TileEntity createNewTileEntity(World worldIn, int meta) {
|
public TileEntity createNewTileEntity(World worldIn, int meta) {
|
||||||
return new TileWaterMill();
|
return new TileWaterMill();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IMachineGuiHandler getGui() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -26,41 +26,31 @@ package techreborn.blocks.storage;
|
||||||
|
|
||||||
import com.google.common.base.Predicate;
|
import com.google.common.base.Predicate;
|
||||||
import com.google.common.collect.Iterators;
|
import com.google.common.collect.Iterators;
|
||||||
import net.minecraft.block.BlockDynamicLiquid;
|
|
||||||
import net.minecraft.block.BlockStaticLiquid;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.block.material.Material;
|
import net.minecraft.block.material.Material;
|
||||||
import net.minecraft.block.properties.PropertyDirection;
|
import net.minecraft.block.properties.PropertyDirection;
|
||||||
import net.minecraft.block.state.BlockStateContainer;
|
import net.minecraft.block.state.BlockStateContainer;
|
||||||
import net.minecraft.block.state.IBlockState;
|
import net.minecraft.block.state.IBlockState;
|
||||||
import net.minecraft.entity.EntityLivingBase;
|
import net.minecraft.entity.EntityLivingBase;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.init.Blocks;
|
|
||||||
import net.minecraft.inventory.IInventory;
|
|
||||||
import net.minecraft.item.ItemBlock;
|
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
import net.minecraft.util.EnumFacing;
|
import net.minecraft.util.EnumFacing;
|
||||||
import net.minecraft.util.EnumHand;
|
import net.minecraft.util.EnumHand;
|
||||||
import net.minecraft.util.SoundCategory;
|
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import net.minecraftforge.fluids.BlockFluidBase;
|
|
||||||
import prospector.shootingstar.ShootingStar;
|
import prospector.shootingstar.ShootingStar;
|
||||||
import prospector.shootingstar.model.ModelCompound;
|
import prospector.shootingstar.model.ModelCompound;
|
||||||
import reborncore.api.IToolDrop;
|
|
||||||
import reborncore.api.ToolManager;
|
import reborncore.api.ToolManager;
|
||||||
import reborncore.api.tile.IUpgradeable;
|
|
||||||
import reborncore.common.BaseTileBlock;
|
import reborncore.common.BaseTileBlock;
|
||||||
import reborncore.common.blocks.BlockWrenchEventHandler;
|
import reborncore.common.blocks.BlockWrenchEventHandler;
|
||||||
import reborncore.common.util.WorldUtils;
|
import reborncore.common.items.WrenchHelper;
|
||||||
import techreborn.Core;
|
import techreborn.Core;
|
||||||
import techreborn.client.TechRebornCreativeTab;
|
import techreborn.client.TechRebornCreativeTab;
|
||||||
import techreborn.init.ModSounds;
|
|
||||||
import techreborn.lib.ModInfo;
|
import techreborn.lib.ModInfo;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -82,119 +72,6 @@ public abstract class BlockEnergyStorage extends BaseTileBlock {
|
||||||
BlockWrenchEventHandler.wrenableBlocks.add(this);
|
BlockWrenchEventHandler.wrenableBlocks.add(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand,
|
|
||||||
EnumFacing side, float hitX, float hitY, float hitZ) {
|
|
||||||
ItemStack heldStack = player.getHeldItem(EnumHand.MAIN_HAND);
|
|
||||||
if(ToolManager.INSTANCE.canHandleTool(heldStack)){
|
|
||||||
if(ToolManager.INSTANCE.handleTool(heldStack, pos, world, player, side, true)){
|
|
||||||
if (player.isSneaking()) {
|
|
||||||
TileEntity tileEntity = world.getTileEntity(pos);
|
|
||||||
if (tileEntity instanceof IToolDrop) {
|
|
||||||
dropInventory(world, pos);
|
|
||||||
ItemStack drop = ((IToolDrop) tileEntity).getToolDrop(player);
|
|
||||||
if (drop == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (!drop.isEmpty()) {
|
|
||||||
spawnAsEntity(world, pos, drop);
|
|
||||||
}
|
|
||||||
world.playSound(null, player.posX, player.posY, player.posZ, ModSounds.BLOCK_DISMANTLE,
|
|
||||||
SoundCategory.BLOCKS, 0.6F, 1F);
|
|
||||||
if (!world.isRemote) {
|
|
||||||
world.setBlockState(pos, Blocks.AIR.getDefaultState(), 2);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
EnumFacing facing2 = state.getValue(BlockEnergyStorage.FACING);
|
|
||||||
if (facing2.getOpposite() == side) {
|
|
||||||
facing2 = side;
|
|
||||||
} else {
|
|
||||||
facing2 = side.getOpposite();
|
|
||||||
}
|
|
||||||
world.setBlockState(pos, state.withProperty(BlockEnergyStorage.FACING, facing2));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (!player.isSneaking()){
|
|
||||||
player.openGui(Core.INSTANCE, guiID, world, pos.getX(), pos.getY(), pos.getZ());
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return super.onBlockActivated(world, pos, state, player, hand, side, hitX, hitY, hitZ);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void dropInventory(World world, BlockPos pos) {
|
|
||||||
TileEntity tileEntity = world.getTileEntity(pos);
|
|
||||||
|
|
||||||
if (tileEntity == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!(tileEntity instanceof IInventory)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
IInventory inventory = (IInventory) tileEntity;
|
|
||||||
List<ItemStack> items = new ArrayList<ItemStack>();
|
|
||||||
addItemsToList(inventory, items);
|
|
||||||
if (tileEntity instanceof IUpgradeable) {
|
|
||||||
addItemsToList(((IUpgradeable) tileEntity).getUpgradeInvetory(), items);
|
|
||||||
}
|
|
||||||
WorldUtils.dropItems(items, world, pos);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void addItemsToList(IInventory inventory, List<ItemStack> items) {
|
|
||||||
for (int i = 0; i < inventory.getSizeInventory(); i++) {
|
|
||||||
ItemStack itemStack = inventory.getStackInSlot(i);
|
|
||||||
|
|
||||||
if (itemStack == ItemStack.EMPTY) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (itemStack != ItemStack.EMPTY && itemStack.getCount() > 0) {
|
|
||||||
if (itemStack.getItem() instanceof ItemBlock) {
|
|
||||||
if (((ItemBlock) itemStack.getItem()).getBlock() instanceof BlockFluidBase
|
|
||||||
|| ((ItemBlock) itemStack.getItem()).getBlock() instanceof BlockStaticLiquid
|
|
||||||
|| ((ItemBlock) itemStack.getItem()).getBlock() instanceof BlockDynamicLiquid) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
items.add(itemStack.copy());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected BlockStateContainer createBlockState() {
|
|
||||||
FACING = PropertyDirection.create("facing", Facings.ALL);
|
|
||||||
return new BlockStateContainer(this, FACING);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer,
|
|
||||||
ItemStack stack) {
|
|
||||||
super.onBlockPlacedBy(worldIn, pos, state, placer, stack);
|
|
||||||
EnumFacing facing = placer.getHorizontalFacing().getOpposite();
|
|
||||||
if (placer.rotationPitch < -50) {
|
|
||||||
facing = EnumFacing.DOWN;
|
|
||||||
} else if (placer.rotationPitch > 50) {
|
|
||||||
facing = EnumFacing.UP;
|
|
||||||
}
|
|
||||||
setFacing(facing, worldIn, pos);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getMetaFromState(IBlockState state) {
|
|
||||||
int facingInt = getSideFromEnum(state.getValue(FACING));
|
|
||||||
return facingInt;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IBlockState getStateFromMeta(int meta) {
|
|
||||||
EnumFacing facing = getSideFromint(meta);
|
|
||||||
return this.getDefaultState().withProperty(FACING, facing);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setFacing(EnumFacing facing, World world, BlockPos pos) {
|
public void setFacing(EnumFacing facing, World world, BlockPos pos) {
|
||||||
world.setBlockState(pos, world.getBlockState(pos).withProperty(FACING, facing));
|
world.setBlockState(pos, world.getBlockState(pos).withProperty(FACING, facing));
|
||||||
}
|
}
|
||||||
|
@ -259,6 +136,81 @@ public abstract class BlockEnergyStorage extends BaseTileBlock {
|
||||||
return fullName.toLowerCase();
|
return fullName.toLowerCase();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Block
|
||||||
|
@Override
|
||||||
|
public boolean rotateBlock(World world, BlockPos pos, EnumFacing side) {
|
||||||
|
IBlockState state = world.getBlockState(pos);
|
||||||
|
Block block = state.getBlock();
|
||||||
|
if (block instanceof BlockEnergyStorage) {
|
||||||
|
EnumFacing facing = state.getValue(BlockEnergyStorage.FACING);
|
||||||
|
if (facing.getOpposite() == side) {
|
||||||
|
facing = side;
|
||||||
|
} else {
|
||||||
|
facing = side.getOpposite();
|
||||||
|
}
|
||||||
|
world.setBlockState(pos, state.withProperty(BlockEnergyStorage.FACING, facing));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand,
|
||||||
|
EnumFacing side, float hitX, float hitY, float hitZ) {
|
||||||
|
ItemStack stack = playerIn.getHeldItem(EnumHand.MAIN_HAND);
|
||||||
|
TileEntity tileEntity = worldIn.getTileEntity(pos);
|
||||||
|
|
||||||
|
// We extended BlockTileBase. Thus we should always have tile entity. I hope.
|
||||||
|
if (tileEntity == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!stack.isEmpty() && ToolManager.INSTANCE.canHandleTool(stack)) {
|
||||||
|
if (WrenchHelper.handleWrench(stack, worldIn, pos, playerIn, side)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!playerIn.isSneaking()) {
|
||||||
|
playerIn.openGui(Core.INSTANCE, guiID, worldIn, pos.getX(), pos.getY(), pos.getZ());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return super.onBlockActivated(worldIn, pos, state, playerIn, hand, side, hitX, hitY, hitZ);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected BlockStateContainer createBlockState() {
|
||||||
|
FACING = PropertyDirection.create("facing", Facings.ALL);
|
||||||
|
return new BlockStateContainer(this, FACING);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer,
|
||||||
|
ItemStack stack) {
|
||||||
|
super.onBlockPlacedBy(worldIn, pos, state, placer, stack);
|
||||||
|
EnumFacing facing = placer.getHorizontalFacing().getOpposite();
|
||||||
|
if (placer.rotationPitch < -50) {
|
||||||
|
facing = EnumFacing.DOWN;
|
||||||
|
} else if (placer.rotationPitch > 50) {
|
||||||
|
facing = EnumFacing.UP;
|
||||||
|
}
|
||||||
|
setFacing(facing, worldIn, pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getMetaFromState(IBlockState state) {
|
||||||
|
int facingInt = getSideFromEnum(state.getValue(FACING));
|
||||||
|
return facingInt;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IBlockState getStateFromMeta(int meta) {
|
||||||
|
EnumFacing facing = getSideFromint(meta);
|
||||||
|
return this.getDefaultState().withProperty(FACING, facing);
|
||||||
|
}
|
||||||
|
|
||||||
public enum Facings implements Predicate<EnumFacing>, Iterable<EnumFacing> {
|
public enum Facings implements Predicate<EnumFacing>, Iterable<EnumFacing> {
|
||||||
ALL;
|
ALL;
|
||||||
|
|
||||||
|
|
|
@ -26,38 +26,30 @@ package techreborn.blocks.transformers;
|
||||||
|
|
||||||
import com.google.common.base.Predicate;
|
import com.google.common.base.Predicate;
|
||||||
import com.google.common.collect.Iterators;
|
import com.google.common.collect.Iterators;
|
||||||
import net.minecraft.block.BlockDynamicLiquid;
|
|
||||||
import net.minecraft.block.BlockStaticLiquid;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.block.material.Material;
|
import net.minecraft.block.material.Material;
|
||||||
import net.minecraft.block.properties.PropertyDirection;
|
import net.minecraft.block.properties.PropertyDirection;
|
||||||
import net.minecraft.block.state.BlockStateContainer;
|
import net.minecraft.block.state.BlockStateContainer;
|
||||||
import net.minecraft.block.state.IBlockState;
|
import net.minecraft.block.state.IBlockState;
|
||||||
import net.minecraft.entity.EntityLivingBase;
|
import net.minecraft.entity.EntityLivingBase;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.init.Blocks;
|
|
||||||
import net.minecraft.inventory.IInventory;
|
|
||||||
import net.minecraft.item.ItemBlock;
|
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
import net.minecraft.util.EnumFacing;
|
import net.minecraft.util.EnumFacing;
|
||||||
import net.minecraft.util.EnumHand;
|
import net.minecraft.util.EnumHand;
|
||||||
import net.minecraft.util.SoundCategory;
|
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.world.IBlockAccess;
|
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import net.minecraftforge.fluids.BlockFluidBase;
|
|
||||||
import prospector.shootingstar.ShootingStar;
|
import prospector.shootingstar.ShootingStar;
|
||||||
import prospector.shootingstar.model.ModelCompound;
|
import prospector.shootingstar.model.ModelCompound;
|
||||||
import reborncore.api.IToolDrop;
|
|
||||||
import reborncore.api.ToolManager;
|
import reborncore.api.ToolManager;
|
||||||
import reborncore.common.BaseTileBlock;
|
import reborncore.common.BaseTileBlock;
|
||||||
|
import reborncore.common.blocks.BlockWrenchEventHandler;
|
||||||
|
import reborncore.common.items.WrenchHelper;
|
||||||
import techreborn.client.TechRebornCreativeTab;
|
import techreborn.client.TechRebornCreativeTab;
|
||||||
import techreborn.init.ModSounds;
|
|
||||||
import techreborn.lib.ModInfo;
|
import techreborn.lib.ModInfo;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -74,139 +66,17 @@ public abstract class BlockTransformer extends BaseTileBlock {
|
||||||
this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH));
|
this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH));
|
||||||
this.name = name;
|
this.name = name;
|
||||||
ShootingStar.registerModel(new ModelCompound(ModInfo.MOD_ID, this, "machines/energy"));
|
ShootingStar.registerModel(new ModelCompound(ModInfo.MOD_ID, this, "machines/energy"));
|
||||||
}
|
BlockWrenchEventHandler.wrenableBlocks.add(this);
|
||||||
|
|
||||||
@Override
|
|
||||||
protected BlockStateContainer createBlockState() {
|
|
||||||
FACING = PropertyDirection.create("facing", Facings.ALL);
|
|
||||||
return new BlockStateContainer(this, FACING);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onBlockAdded(World worldIn, BlockPos pos, IBlockState state) {
|
|
||||||
super.onBlockAdded(worldIn, pos, state);
|
|
||||||
this.setDefaultFacing(worldIn, pos, state);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void setDefaultFacing(World worldIn, BlockPos pos, IBlockState state) {
|
|
||||||
if (!worldIn.isRemote) {
|
|
||||||
IBlockState state0 = worldIn.getBlockState(pos.north());
|
|
||||||
IBlockState state1 = worldIn.getBlockState(pos.south());
|
|
||||||
IBlockState state2 = worldIn.getBlockState(pos.west());
|
|
||||||
IBlockState state3 = worldIn.getBlockState(pos.east());
|
|
||||||
EnumFacing enumfacing = (EnumFacing) state.getValue(FACING);
|
|
||||||
|
|
||||||
if (enumfacing == EnumFacing.NORTH && state0.isFullBlock() && !state1.isFullBlock()) {
|
|
||||||
enumfacing = EnumFacing.SOUTH;
|
|
||||||
} else if (enumfacing == EnumFacing.SOUTH && state1.isFullBlock() && !state0.isFullBlock()) {
|
|
||||||
enumfacing = EnumFacing.NORTH;
|
|
||||||
} else if (enumfacing == EnumFacing.WEST && state2.isFullBlock() && !state3.isFullBlock()) {
|
|
||||||
enumfacing = EnumFacing.EAST;
|
|
||||||
} else if (enumfacing == EnumFacing.EAST && state3.isFullBlock() && !state2.isFullBlock()) {
|
|
||||||
enumfacing = EnumFacing.WEST;
|
|
||||||
}
|
|
||||||
|
|
||||||
worldIn.setBlockState(pos, state.withProperty(FACING, enumfacing), 2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer,
|
|
||||||
ItemStack stack) {
|
|
||||||
super.onBlockPlacedBy(worldIn, pos, state, placer, stack);
|
|
||||||
EnumFacing facing = placer.getHorizontalFacing().getOpposite();
|
|
||||||
if (placer.rotationPitch < -50) {
|
|
||||||
facing = EnumFacing.DOWN;
|
|
||||||
} else if (placer.rotationPitch > 50) {
|
|
||||||
facing = EnumFacing.UP;
|
|
||||||
}
|
|
||||||
setFacing(facing, worldIn, pos);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand,
|
|
||||||
EnumFacing side, float hitX, float hitY, float hitZ) {
|
|
||||||
ItemStack stack = player.getHeldItem(EnumHand.MAIN_HAND);
|
|
||||||
if(!stack.isEmpty() && ToolManager.INSTANCE.canHandleTool(stack) && !world.isRemote){
|
|
||||||
if(ToolManager.INSTANCE.handleTool(stack, pos, world, player, side, true) && state.getBlock() instanceof BlockTransformer){
|
|
||||||
if (player.isSneaking()) {
|
|
||||||
TileEntity tileEntity = world.getTileEntity(pos);
|
|
||||||
if (tileEntity instanceof IToolDrop) {
|
|
||||||
ItemStack drop = ((IToolDrop) tileEntity).getToolDrop(player);
|
|
||||||
dropInventory(world, pos, drop);
|
|
||||||
world.playSound(null, player.posX, player.posY, player.posZ, ModSounds.BLOCK_DISMANTLE,
|
|
||||||
SoundCategory.BLOCKS, 0.6F, 1F);
|
|
||||||
if (!world.isRemote) {
|
|
||||||
world.setBlockState(pos, Blocks.AIR.getDefaultState(), 2);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
EnumFacing facing2 = state.getValue(BlockTransformer.FACING);
|
|
||||||
if (facing2.getOpposite() == side) {
|
|
||||||
facing2 = side;
|
|
||||||
} else {
|
|
||||||
facing2 = side.getOpposite();
|
|
||||||
}
|
|
||||||
world.setBlockState(pos, state.withProperty(BlockTransformer.FACING, facing2));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return super.onBlockActivated(world, pos, state, player, hand, side, hitX, hitY, hitZ);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected List<ItemStack> dropInventory(IBlockAccess world, BlockPos pos, ItemStack itemToDrop) {
|
|
||||||
TileEntity tileEntity = world.getTileEntity(pos);
|
|
||||||
if (!(tileEntity instanceof IInventory)) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
IInventory inventory = (IInventory) tileEntity;
|
|
||||||
|
|
||||||
List<ItemStack> items = new ArrayList<>();
|
|
||||||
|
|
||||||
for (int i = 0; i < inventory.getSizeInventory(); i++) {
|
|
||||||
ItemStack itemStack = inventory.getStackInSlot(i);
|
|
||||||
|
|
||||||
if (itemStack.isEmpty()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (!itemStack.isEmpty() && itemStack.getCount() > 0) {
|
|
||||||
if (itemStack.getItem() instanceof ItemBlock) {
|
|
||||||
if (((ItemBlock) itemStack.getItem()).getBlock() instanceof BlockFluidBase
|
|
||||||
|| ((ItemBlock) itemStack.getItem()).getBlock() instanceof BlockStaticLiquid
|
|
||||||
|| ((ItemBlock) itemStack.getItem()).getBlock() instanceof BlockDynamicLiquid) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
items.add(itemStack.copy());
|
|
||||||
}
|
|
||||||
if(!itemToDrop.isEmpty()){
|
|
||||||
items.add(itemToDrop.copy());
|
|
||||||
}
|
|
||||||
return items;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getMetaFromState(IBlockState state) {
|
|
||||||
int facingInt = getSideFromEnum(state.getValue(FACING));
|
|
||||||
return facingInt;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IBlockState getStateFromMeta(int meta) {
|
|
||||||
EnumFacing facing = getSideFromint(meta);
|
|
||||||
return this.getDefaultState().withProperty(FACING, facing);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setFacing(EnumFacing facing, World world, BlockPos pos) {
|
public void setFacing(EnumFacing facing, World world, BlockPos pos) {
|
||||||
world.setBlockState(pos, world.getBlockState(pos).withProperty(FACING, facing));
|
world.setBlockState(pos, world.getBlockState(pos).withProperty(FACING, facing));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public EnumFacing getFacing(IBlockState state) {
|
||||||
|
return state.getValue(FACING);
|
||||||
|
}
|
||||||
|
|
||||||
public EnumFacing getSideFromint(int i) {
|
public EnumFacing getSideFromint(int i) {
|
||||||
if (i == 0) {
|
if (i == 0) {
|
||||||
return EnumFacing.NORTH;
|
return EnumFacing.NORTH;
|
||||||
|
@ -241,8 +111,102 @@ public abstract class BlockTransformer extends BaseTileBlock {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public EnumFacing getFacing(IBlockState state) {
|
private void setDefaultFacing(World worldIn, BlockPos pos, IBlockState state) {
|
||||||
return state.getValue(FACING);
|
if (!worldIn.isRemote) {
|
||||||
|
IBlockState state0 = worldIn.getBlockState(pos.north());
|
||||||
|
IBlockState state1 = worldIn.getBlockState(pos.south());
|
||||||
|
IBlockState state2 = worldIn.getBlockState(pos.west());
|
||||||
|
IBlockState state3 = worldIn.getBlockState(pos.east());
|
||||||
|
EnumFacing enumfacing = (EnumFacing) state.getValue(FACING);
|
||||||
|
|
||||||
|
if (enumfacing == EnumFacing.NORTH && state0.isFullBlock() && !state1.isFullBlock()) {
|
||||||
|
enumfacing = EnumFacing.SOUTH;
|
||||||
|
} else if (enumfacing == EnumFacing.SOUTH && state1.isFullBlock() && !state0.isFullBlock()) {
|
||||||
|
enumfacing = EnumFacing.NORTH;
|
||||||
|
} else if (enumfacing == EnumFacing.WEST && state2.isFullBlock() && !state3.isFullBlock()) {
|
||||||
|
enumfacing = EnumFacing.EAST;
|
||||||
|
} else if (enumfacing == EnumFacing.EAST && state3.isFullBlock() && !state2.isFullBlock()) {
|
||||||
|
enumfacing = EnumFacing.WEST;
|
||||||
|
}
|
||||||
|
|
||||||
|
worldIn.setBlockState(pos, state.withProperty(FACING, enumfacing), 2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Block
|
||||||
|
@Override
|
||||||
|
protected BlockStateContainer createBlockState() {
|
||||||
|
FACING = PropertyDirection.create("facing", Facings.ALL);
|
||||||
|
return new BlockStateContainer(this, FACING);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBlockAdded(World worldIn, BlockPos pos, IBlockState state) {
|
||||||
|
super.onBlockAdded(worldIn, pos, state);
|
||||||
|
this.setDefaultFacing(worldIn, pos, state);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer,
|
||||||
|
ItemStack stack) {
|
||||||
|
super.onBlockPlacedBy(worldIn, pos, state, placer, stack);
|
||||||
|
EnumFacing facing = placer.getHorizontalFacing().getOpposite();
|
||||||
|
if (placer.rotationPitch < -50) {
|
||||||
|
facing = EnumFacing.DOWN;
|
||||||
|
} else if (placer.rotationPitch > 50) {
|
||||||
|
facing = EnumFacing.UP;
|
||||||
|
}
|
||||||
|
setFacing(facing, worldIn, pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand,
|
||||||
|
EnumFacing side, float hitX, float hitY, float hitZ) {
|
||||||
|
ItemStack stack = playerIn.getHeldItem(EnumHand.MAIN_HAND);
|
||||||
|
TileEntity tileEntity = worldIn.getTileEntity(pos);
|
||||||
|
|
||||||
|
// We extended BlockTileBase. Thus we should always have tile entity. I hope.
|
||||||
|
if (tileEntity == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!stack.isEmpty() && ToolManager.INSTANCE.canHandleTool(stack)) {
|
||||||
|
if (WrenchHelper.handleWrench(stack, worldIn, pos, playerIn, side)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return super.onBlockActivated(worldIn, pos, state, playerIn, hand, side, hitX, hitY, hitZ);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean rotateBlock(World world, BlockPos pos, EnumFacing side) {
|
||||||
|
IBlockState state = world.getBlockState(pos);
|
||||||
|
Block block = state.getBlock();
|
||||||
|
if (block instanceof BlockTransformer) {
|
||||||
|
EnumFacing facing = state.getValue(BlockTransformer.FACING);
|
||||||
|
if (facing.getOpposite() == side) {
|
||||||
|
facing = side;
|
||||||
|
} else {
|
||||||
|
facing = side.getOpposite();
|
||||||
|
}
|
||||||
|
world.setBlockState(pos, state.withProperty(BlockTransformer.FACING, facing));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getMetaFromState(IBlockState state) {
|
||||||
|
int facingInt = getSideFromEnum(state.getValue(FACING));
|
||||||
|
return facingInt;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IBlockState getStateFromMeta(int meta) {
|
||||||
|
EnumFacing facing = getSideFromint(meta);
|
||||||
|
return this.getDefaultState().withProperty(FACING, facing);
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum Facings implements Predicate<EnumFacing>, Iterable<EnumFacing> {
|
public enum Facings implements Predicate<EnumFacing>, Iterable<EnumFacing> {
|
||||||
|
|
Loading…
Add table
Reference in a new issue