Updated onBlockActivated

This commit is contained in:
drcrazy 2019-02-21 13:35:54 +03:00
parent 8489259672
commit bdb8834a3e
13 changed files with 31 additions and 127 deletions

View file

@ -110,8 +110,7 @@ public class BlockAlarm extends BaseTileBlock {
} }
@Override @Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, public boolean onBlockActivated(IBlockState state, World worldIn, BlockPos pos, EntityPlayer playerIn, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
ItemStack stack = playerIn.getHeldItem(EnumHand.MAIN_HAND); ItemStack stack = playerIn.getHeldItem(EnumHand.MAIN_HAND);
TileEntity tileEntity = worldIn.getTileEntity(pos); TileEntity tileEntity = worldIn.getTileEntity(pos);
@ -132,21 +131,7 @@ public class BlockAlarm extends BaseTileBlock {
} }
return super.onBlockActivated(worldIn, pos, state, playerIn, hand, side, hitX, hitY, hitZ); return super.onBlockActivated(state, worldIn, pos, playerIn, hand, side, hitX, hitY, hitZ);
}
@Override
public int getMetaFromState(IBlockState state) {
int facingInt = state.getValue(FACING).getIndex();
int activeInt = state.getValue(ACTIVE) ? 8 : 0;
return facingInt + activeInt;
}
@Override
public IBlockState getStateFromMeta(int meta) {
Boolean active = (meta & 8) == 8;
EnumFacing facing = EnumFacing.byIndex(meta & 7);
return this.getDefaultState().with(FACING, facing).with(ACTIVE, active);
} }
@Nullable @Nullable

View file

@ -55,8 +55,7 @@ public class BlockComputerCube extends BlockMachineBase {
} }
@Override @Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, public boolean onBlockActivated(IBlockState state, World worldIn, BlockPos pos, EntityPlayer playerIn, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
ItemStack tool = playerIn.getHeldItem(EnumHand.MAIN_HAND); ItemStack tool = playerIn.getHeldItem(EnumHand.MAIN_HAND);
if (!tool.isEmpty() && ToolManager.INSTANCE.canHandleTool(tool)) { if (!tool.isEmpty() && ToolManager.INSTANCE.canHandleTool(tool)) {

View file

@ -110,12 +110,6 @@ public class BlockNuke extends BaseBlock {
} }
} }
@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn,
EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
return false;
}
@Override @Override
public int getMetaFromState(IBlockState state) { public int getMetaFromState(IBlockState state) {
return state.getValue(OVERLAY) ? 1 : 0; return state.getValue(OVERLAY) ? 1 : 0;

View file

@ -161,9 +161,8 @@ public class BlockRubberLog extends Block {
} }
@Override @Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, public boolean onBlockActivated(IBlockState state, World worldIn, BlockPos pos, EntityPlayer playerIn, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) { super.onBlockActivated(state, worldIn, pos, playerIn, hand, side, hitX, hitY, hitZ);
super.onBlockActivated(worldIn, pos, state, playerIn, hand, side, hitX, hitY, hitZ);
ItemStack stack = playerIn.getHeldItem(EnumHand.MAIN_HAND); ItemStack stack = playerIn.getHeldItem(EnumHand.MAIN_HAND);
if (stack.isEmpty()) { if (stack.isEmpty()) {
return false; return false;

View file

@ -31,7 +31,6 @@ import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextComponentString; import net.minecraft.util.text.TextComponentString;
import net.minecraft.util.text.TextFormatting; import net.minecraft.util.text.TextFormatting;
import net.minecraft.world.IBlockReader; import net.minecraft.world.IBlockReader;
import net.minecraft.world.World;
import reborncore.api.tile.IMachineGuiHandler; import reborncore.api.tile.IMachineGuiHandler;
import reborncore.common.blocks.BlockMachineBase; import reborncore.common.blocks.BlockMachineBase;
import java.util.List; import java.util.List;
@ -41,8 +40,6 @@ import javax.annotation.Nullable;
public class BlockSupercondensator extends BlockMachineBase { public class BlockSupercondensator extends BlockMachineBase {
public BlockSupercondensator(Material material) { public BlockSupercondensator(Material material) {
super(); super();
setTranslationKey("techreborn.supercondensator");
// setCreativeTab(TechRebornCreativeTab.instance);
} }
@Override @Override

View file

@ -56,9 +56,9 @@ public class BlockFusionCoil extends Block {
super(Block.Properties.create(Material.IRON).hardnessAndResistance(2f).sound(SoundType.METAL)); super(Block.Properties.create(Material.IRON).hardnessAndResistance(2f).sound(SoundType.METAL));
RebornModelRegistry.registerModel(new ModelCompound(TechReborn.MOD_ID, this, "machines/generators")); RebornModelRegistry.registerModel(new ModelCompound(TechReborn.MOD_ID, this, "machines/generators"));
} }
@Override @Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, public boolean onBlockActivated(IBlockState state, World worldIn, BlockPos pos, EntityPlayer playerIn,
EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) { EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
ItemStack tool = playerIn.getHeldItem(EnumHand.MAIN_HAND); ItemStack tool = playerIn.getHeldItem(EnumHand.MAIN_HAND);
@ -78,12 +78,13 @@ public class BlockFusionCoil extends Block {
} }
return false; return false;
} }
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
@Override @Override
public void addInformation(ItemStack stack, @Nullable IBlockReader worldIn, List<ITextComponent> tooltip, ITooltipFlag flagIn) { public void addInformation(ItemStack stack, @Nullable IBlockReader worldIn, List<ITextComponent> tooltip,
ITooltipFlag flagIn) {
super.addInformation(stack, worldIn, tooltip, flagIn); super.addInformation(stack, worldIn, tooltip, flagIn);
//TODO: Translate // TODO: Translate
tooltip.add(new TextComponentString("Right click Fusion Control computer to auto place")); tooltip.add(new TextComponentString("Right click Fusion Control computer to auto place"));
} }
} }

View file

@ -55,21 +55,20 @@ public class BlockFusionControlComputer extends BlockMachineBase {
} }
@Override @Override
public boolean onBlockActivated(final World world, final BlockPos pos, final IBlockState state, public boolean onBlockActivated(IBlockState state, World worldIn, BlockPos pos, EntityPlayer playerIn,
final EntityPlayer player, final EnumHand hand, final EnumFacing side, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
final float hitX, final float hitY, final float hitZ) { final TileFusionControlComputer tileFusionControlComputer = (TileFusionControlComputer) worldIn.getTileEntity(pos);
final TileFusionControlComputer tileFusionControlComputer = (TileFusionControlComputer) world.getTileEntity(pos); if(!playerIn.getHeldItem(hand).isEmpty() && playerIn.getHeldItem(hand).getItem() == Item.getItemFromBlock(TRContent.Machine.FUSION_COIL.block)){
if(!player.getHeldItem(hand).isEmpty() && player.getHeldItem(hand).getItem() == Item.getItemFromBlock(TRContent.Machine.FUSION_COIL.block)){
List<BlockPos> coils = Torus.generate(tileFusionControlComputer.getPos(), tileFusionControlComputer.size); List<BlockPos> coils = Torus.generate(tileFusionControlComputer.getPos(), tileFusionControlComputer.size);
boolean placed = false; boolean placed = false;
for(BlockPos coil : coils){ for(BlockPos coil : coils){
if(player.getHeldItem(hand).isEmpty()){ if(playerIn.getHeldItem(hand).isEmpty()){
return true; return true;
} }
if(world.isAirBlock(coil) && !tileFusionControlComputer.isCoil(coil)){ if(worldIn.isAirBlock(coil) && !tileFusionControlComputer.isCoil(coil)){
world.setBlockState(coil, TRContent.Machine.FUSION_COIL.block.getDefaultState()); worldIn.setBlockState(coil, TRContent.Machine.FUSION_COIL.block.getDefaultState());
if(!player.isCreative()){ if(!playerIn.isCreative()){
player.getHeldItem(hand).shrink(1); playerIn.getHeldItem(hand).shrink(1);
} }
placed = true; placed = true;
} }
@ -80,7 +79,7 @@ public class BlockFusionControlComputer extends BlockMachineBase {
} }
tileFusionControlComputer.checkCoils(); tileFusionControlComputer.checkCoils();
return super.onBlockActivated(world, pos, state, player, hand, side, hitX, hitY, hitZ); return super.onBlockActivated(state, worldIn, pos, playerIn, hand, side, hitX, hitY, hitZ);
} }
@Override @Override

View file

@ -137,16 +137,6 @@ public class BlockLamp extends BaseTileBlock {
return BlockRenderLayer.CUTOUT; return BlockRenderLayer.CUTOUT;
} }
@Override
public boolean isOpaqueCube(IBlockState state) {
return false;
}
@Override
public boolean isFullBlock(IBlockState state) {
return false;
}
@Override @Override
public boolean isFullCube(IBlockState state) { public boolean isFullCube(IBlockState state) {
return false; return false;
@ -167,8 +157,7 @@ public class BlockLamp extends BaseTileBlock {
} }
@Override @Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, public boolean onBlockActivated(IBlockState state, World worldIn, BlockPos pos, EntityPlayer playerIn, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
ItemStack stack = playerIn.getHeldItem(EnumHand.MAIN_HAND); ItemStack stack = playerIn.getHeldItem(EnumHand.MAIN_HAND);
TileEntity tileEntity = worldIn.getTileEntity(pos); TileEntity tileEntity = worldIn.getTileEntity(pos);
@ -183,7 +172,7 @@ public class BlockLamp extends BaseTileBlock {
} }
} }
return super.onBlockActivated(worldIn, pos, state, playerIn, hand, side, hitX, hitY, hitZ); return super.onBlockActivated(state, worldIn, pos, playerIn, hand, side, hitX, hitY, hitZ);
} }
@Override @Override

View file

@ -150,8 +150,7 @@ public abstract class BlockEnergyStorage extends BaseTileBlock {
} }
@Override @Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, public boolean onBlockActivated(IBlockState state, World worldIn, BlockPos pos, EntityPlayer playerIn, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
EnumFacing side, float hitX, float hitY, float hitZ) {
ItemStack stack = playerIn.getHeldItem(EnumHand.MAIN_HAND); ItemStack stack = playerIn.getHeldItem(EnumHand.MAIN_HAND);
TileEntity tileEntity = worldIn.getTileEntity(pos); TileEntity tileEntity = worldIn.getTileEntity(pos);
@ -193,18 +192,6 @@ public abstract class BlockEnergyStorage extends BaseTileBlock {
setFacing(facing, worldIn, pos); 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().with(FACING, facing);
}
public enum Facings implements Predicate<EnumFacing>, Iterable<EnumFacing> { public enum Facings implements Predicate<EnumFacing>, Iterable<EnumFacing> {
ALL; ALL;

View file

@ -89,8 +89,7 @@ public class BlockLSUStorage extends BaseTileBlock {
} }
@Override @Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, public boolean onBlockActivated(IBlockState state, World worldIn, BlockPos pos, EntityPlayer playerIn, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
EnumFacing side, float hitX, float hitY, float hitZ) {
ItemStack stack = playerIn.getHeldItem(EnumHand.MAIN_HAND); ItemStack stack = playerIn.getHeldItem(EnumHand.MAIN_HAND);
TileEntity tileEntity = worldIn.getTileEntity(pos); TileEntity tileEntity = worldIn.getTileEntity(pos);
@ -105,7 +104,7 @@ public class BlockLSUStorage extends BaseTileBlock {
} }
} }
return super.onBlockActivated(worldIn, pos, state, playerIn, hand, side, hitX, hitY, hitZ); return super.onBlockActivated(state, worldIn, pos, playerIn, hand, side, hitX, hitY, hitZ);
} }
@Override @Override

View file

@ -24,11 +24,8 @@
package techreborn.blocks.tier1; package techreborn.blocks.tier1;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.IBlockReader; import net.minecraft.world.IBlockReader;
import net.minecraft.world.World;
import reborncore.api.tile.IMachineGuiHandler; import reborncore.api.tile.IMachineGuiHandler;
import reborncore.client.models.ModelCompound; import reborncore.client.models.ModelCompound;
import reborncore.client.models.RebornModelRegistry; import reborncore.client.models.RebornModelRegistry;
@ -40,25 +37,10 @@ import techreborn.tiles.machine.tier1.TileAutoCraftingTable;
public class BlockAutoCraftingTable extends BlockMachineBase { public class BlockAutoCraftingTable extends BlockMachineBase {
public BlockAutoCraftingTable() { public BlockAutoCraftingTable() {
super(true); super();
RebornModelRegistry.registerModel(new ModelCompound(TechReborn.MOD_ID, this, "machines/tier1_machines")); RebornModelRegistry.registerModel(new ModelCompound(TechReborn.MOD_ID, this, "machines/tier1_machines"));
} }
@Override
protected BlockStateContainer createBlockState() {
return new BlockStateContainer(this);
}
@Override
public int getMetaFromState(IBlockState state) {
return 0;
}
@Override
public IBlockState getStateFromMeta(int meta) {
return getDefaultState();
}
@Override @Override
public TileEntity createNewTileEntity(IBlockReader worldIn) { public TileEntity createNewTileEntity(IBlockReader worldIn) {
return new TileAutoCraftingTable(); return new TileAutoCraftingTable();

View file

@ -94,13 +94,12 @@ public class BlockPlayerDetector extends BlockMachineBase {
} }
@Override @Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, public boolean onBlockActivated(IBlockState state, World worldIn, BlockPos pos, EntityPlayer playerIn, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
ItemStack stack = playerIn.getHeldItem(EnumHand.MAIN_HAND); ItemStack stack = playerIn.getHeldItem(EnumHand.MAIN_HAND);
TileEntity tileEntity = worldIn.getTileEntity(pos); TileEntity tileEntity = worldIn.getTileEntity(pos);
if (tileEntity == null) { if (tileEntity == null) {
return super.onBlockActivated(worldIn, pos, state, playerIn, hand, side, hitX, hitY, hitZ); return super.onBlockActivated(state, worldIn, pos, playerIn, hand, side, hitX, hitY, hitZ);
} }
String type = state.getValue(TYPE); String type = state.getValue(TYPE);
@ -152,19 +151,6 @@ public class BlockPlayerDetector extends BlockMachineBase {
return new BlockStateContainer(this, TYPE); return new BlockStateContainer(this, TYPE);
} }
@Override
public IBlockState getStateFromMeta(int meta) {
if (meta > types.length) {
meta = 0;
}
return getBlockState().getBaseState().with(TYPE, typeNamesList.get(meta));
}
@Override
public int getMetaFromState(IBlockState state) {
return typeNamesList.indexOf(state.getValue(TYPE));
}
@Override @Override
public IMachineGuiHandler getGui() { public IMachineGuiHandler getGui() {
return null; return null;

View file

@ -156,8 +156,7 @@ public abstract class BlockTransformer extends BaseTileBlock {
} }
@Override @Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, public boolean onBlockActivated(IBlockState state, World worldIn, BlockPos pos, EntityPlayer playerIn, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
EnumFacing side, float hitX, float hitY, float hitZ) {
ItemStack stack = playerIn.getHeldItem(EnumHand.MAIN_HAND); ItemStack stack = playerIn.getHeldItem(EnumHand.MAIN_HAND);
TileEntity tileEntity = worldIn.getTileEntity(pos); TileEntity tileEntity = worldIn.getTileEntity(pos);
@ -172,7 +171,7 @@ public abstract class BlockTransformer extends BaseTileBlock {
} }
} }
return super.onBlockActivated(worldIn, pos, state, playerIn, hand, side, hitX, hitY, hitZ); return super.onBlockActivated(state, worldIn, pos, playerIn, hand, side, hitX, hitY, hitZ);
} }
@Override @Override
@ -193,18 +192,6 @@ public abstract class BlockTransformer extends BaseTileBlock {
return false; 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().with(FACING, facing);
}
public enum Facings implements Predicate<EnumFacing>, Iterable<EnumFacing> { public enum Facings implements Predicate<EnumFacing>, Iterable<EnumFacing> {
ALL; ALL;