Updated block wrenching
This commit is contained in:
parent
77e1c54b86
commit
c409b67c3c
8 changed files with 151 additions and 112 deletions
|
@ -45,7 +45,9 @@ import net.minecraft.world.IBlockAccess;
|
|||
import net.minecraft.world.World;
|
||||
import prospector.shootingstar.ShootingStar;
|
||||
import prospector.shootingstar.model.ModelCompound;
|
||||
import reborncore.api.ToolManager;
|
||||
import reborncore.common.BaseTileBlock;
|
||||
import reborncore.common.items.WrenchHelper;
|
||||
import techreborn.client.TechRebornCreativeTab;
|
||||
import techreborn.lib.ModInfo;
|
||||
import techreborn.tiles.TileAlarm;
|
||||
|
@ -88,18 +90,29 @@ public class BlockAlarm extends BaseTileBlock {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
|
||||
TileAlarm tileEntity = (TileAlarm) worldIn.getTileEntity(pos);
|
||||
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 super.onBlockActivated(worldIn, pos, state, playerIn, hand, facing, hitX, hitY, hitZ);
|
||||
} else {
|
||||
if (!worldIn.isRemote) {
|
||||
if (playerIn.isSneaking()) {
|
||||
tileEntity.rightClick();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!stack.isEmpty() && ToolManager.INSTANCE.canHandleTool(stack)) {
|
||||
if (WrenchHelper.handleWrench(stack, worldIn, pos, playerIn, side)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
||||
if (!worldIn.isRemote && playerIn.isSneaking()) {
|
||||
((TileAlarm) tileEntity).rightClick();
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
return super.onBlockActivated(worldIn, pos, state, playerIn, hand, side, hitX, hitY, hitZ);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -167,10 +180,10 @@ public class BlockAlarm extends BaseTileBlock {
|
|||
}
|
||||
|
||||
@Override
|
||||
|
||||
public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos) {
|
||||
return this.bbs[getFacing(state).getIndex()];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addInformation(final ItemStack stack, final World world, final List<String> tooltip, ITooltipFlag flag) {
|
||||
tooltip.add(TextFormatting.GRAY + I18n.format("techreborn.tooltip.alarm"));
|
||||
|
|
|
@ -34,11 +34,14 @@ import net.minecraft.item.Item;
|
|||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import prospector.shootingstar.ShootingStar;
|
||||
import prospector.shootingstar.model.ModelCompound;
|
||||
import reborncore.common.RebornCoreConfig;
|
||||
import reborncore.common.blocks.PropertyString;
|
||||
import reborncore.common.multiblock.BlockMultiblockBase;
|
||||
import reborncore.common.util.ArrayUtils;
|
||||
|
@ -80,6 +83,33 @@ public class BlockMachineCasing extends BlockMultiblockBase {
|
|||
public static ItemStack getStackByName(String name) {
|
||||
return getStackByName(name, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides heat info per casing for Industrial Blast Furnace
|
||||
* @param state Machine casing type
|
||||
* @return Integer Heat value for casing
|
||||
*/
|
||||
public int getHeatFromState(IBlockState state) {
|
||||
switch (getMetaFromState(state)) {
|
||||
case 0:
|
||||
return 1020 / 25;
|
||||
case 1:
|
||||
return 1700 / 25;
|
||||
case 2:
|
||||
return 2380 / 25;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getDrops(NonNullList<ItemStack> drops, IBlockAccess world, BlockPos pos, IBlockState state, int fortune) {
|
||||
if (RebornCoreConfig.wrenchRequired){
|
||||
drops.add(new ItemStack(ModBlocks.MACHINE_FRAMES, 1, 1));
|
||||
}
|
||||
else {
|
||||
super.getDrops(drops, world, pos, state, fortune);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBlockState getStateFromMeta(int meta) {
|
||||
|
@ -99,23 +129,6 @@ public class BlockMachineCasing extends BlockMultiblockBase {
|
|||
return new BlockStateContainer(this, TYPE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides heat info per casing for Industrial Blast Furnace
|
||||
* @param state Machine casing type
|
||||
* @return Integer Heat value for casing
|
||||
*/
|
||||
public int getHeatFromState(IBlockState state) {
|
||||
switch (getMetaFromState(state)) {
|
||||
case 0:
|
||||
return 1020 / 25;
|
||||
case 1:
|
||||
return 1700 / 25;
|
||||
case 2:
|
||||
return 2380 / 25;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Item getItemDropped(IBlockState state, Random rand, int fortune) {
|
||||
return Item.getItemFromBlock(this);
|
||||
|
|
|
@ -77,7 +77,39 @@ public class BlockLamp extends BaseTileBlock {
|
|||
this.brightness = brightness;
|
||||
ShootingStar.registerModel(new ModelCompound(ModInfo.MOD_ID, this, "machines/lighting"));
|
||||
}
|
||||
|
||||
public static boolean isActive(IBlockState state) {
|
||||
return state.getValue(ACTIVE);
|
||||
}
|
||||
|
||||
public static EnumFacing getFacing(IBlockState state) {
|
||||
if(!state.getProperties().containsKey(FACING)){
|
||||
return EnumFacing.NORTH;
|
||||
}
|
||||
return state.getValue(FACING);
|
||||
}
|
||||
|
||||
public static void setFacing(EnumFacing facing, World world, BlockPos pos) {
|
||||
world.setBlockState(pos, world.getBlockState(pos).withProperty(FACING, facing));
|
||||
}
|
||||
|
||||
public static void setActive(Boolean active, World world, BlockPos pos) {
|
||||
EnumFacing facing = (EnumFacing)world.getBlockState(pos).getValue(FACING);
|
||||
IBlockState state = world.getBlockState(pos).withProperty(ACTIVE, active).withProperty(FACING, facing);
|
||||
world.setBlockState(pos, state, 3);
|
||||
}
|
||||
|
||||
public int getCost() {
|
||||
return cost;
|
||||
}
|
||||
|
||||
// BaseTileBlock
|
||||
@Override
|
||||
public TileEntity createNewTileEntity(final World world, final int meta) {
|
||||
return new TileLamp();
|
||||
}
|
||||
|
||||
// Block
|
||||
@Override
|
||||
protected BlockStateContainer createBlockState() {
|
||||
FACING = PropertyDirection.create("facing");
|
||||
|
@ -85,11 +117,6 @@ public class BlockLamp extends BaseTileBlock {
|
|||
return new BlockStateContainer(this, FACING, ACTIVE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity createNewTileEntity(final World world, final int meta) {
|
||||
return new TileLamp();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBlockState getStateForPlacement(World world, BlockPos pos, EnumFacing facing, float hitX, float hitY,
|
||||
float hitZ, int meta, EntityLivingBase placer, EnumHand hand) {
|
||||
|
@ -148,29 +175,4 @@ public class BlockLamp extends BaseTileBlock {
|
|||
EnumFacing facing = EnumFacing.getFront(meta&7);
|
||||
return this.getDefaultState().withProperty(FACING, facing).withProperty(ACTIVE, active);
|
||||
}
|
||||
|
||||
public static boolean isActive(IBlockState state) {
|
||||
return state.getValue(ACTIVE);
|
||||
}
|
||||
|
||||
public static EnumFacing getFacing(IBlockState state) {
|
||||
if(!state.getProperties().containsKey(FACING)){
|
||||
return EnumFacing.NORTH;
|
||||
}
|
||||
return state.getValue(FACING);
|
||||
}
|
||||
|
||||
public static void setFacing(EnumFacing facing, World world, BlockPos pos) {
|
||||
world.setBlockState(pos, world.getBlockState(pos).withProperty(FACING, facing));
|
||||
}
|
||||
|
||||
public static void setActive(Boolean active, World world, BlockPos pos) {
|
||||
EnumFacing facing = (EnumFacing)world.getBlockState(pos).getValue(FACING);
|
||||
IBlockState state = world.getBlockState(pos).withProperty(ACTIVE, active).withProperty(FACING, facing);
|
||||
world.setBlockState(pos, state, 3);
|
||||
}
|
||||
|
||||
public int getCost() {
|
||||
return cost;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,6 +27,7 @@ package techreborn.blocks.transformers;
|
|||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
|
@ -34,9 +35,6 @@ import reborncore.common.RebornCoreConfig;
|
|||
import techreborn.init.ModBlocks;
|
||||
import techreborn.tiles.transformers.TileHVTransformer;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by modmuss50 on 16/03/2016.
|
||||
*/
|
||||
|
@ -50,17 +48,14 @@ public class BlockHVTransformer extends BlockTransformer {
|
|||
public TileEntity createNewTileEntity(final World world, final int meta) {
|
||||
return new TileHVTransformer();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ItemStack> getDrops(final IBlockAccess world, final BlockPos pos, final IBlockState state, final int fortune) {
|
||||
List<ItemStack> items = new ArrayList<ItemStack>();
|
||||
|
||||
public void getDrops(NonNullList<ItemStack> drops, final IBlockAccess world, final BlockPos pos, final IBlockState state, final int fortune) {
|
||||
if (RebornCoreConfig.wrenchRequired){
|
||||
items.add(new ItemStack(ModBlocks.MACHINE_FRAMES, 1, 1));
|
||||
drops.add(new ItemStack(ModBlocks.MACHINE_FRAMES, 1, 1));
|
||||
}
|
||||
else {
|
||||
items.add(new ItemStack(this));
|
||||
drops.add(new ItemStack(this));
|
||||
}
|
||||
|
||||
return items;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,6 +27,7 @@ package techreborn.blocks.transformers;
|
|||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
|
@ -34,9 +35,6 @@ import reborncore.common.RebornCoreConfig;
|
|||
import techreborn.init.ModBlocks;
|
||||
import techreborn.tiles.transformers.TileMVTransformer;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by modmuss50 on 16/03/2016.
|
||||
*/
|
||||
|
@ -52,16 +50,12 @@ public class BlockMVTransformer extends BlockTransformer {
|
|||
}
|
||||
|
||||
@Override
|
||||
public List<ItemStack> getDrops(final IBlockAccess world, final BlockPos pos, final IBlockState state, final int fortune) {
|
||||
List<ItemStack> items = new ArrayList<ItemStack>();
|
||||
|
||||
public void getDrops(NonNullList<ItemStack> drops, final IBlockAccess world, final BlockPos pos, final IBlockState state, final int fortune) {
|
||||
if (RebornCoreConfig.wrenchRequired){
|
||||
items.add(new ItemStack(ModBlocks.MACHINE_FRAMES, 1, 0));
|
||||
drops.add(new ItemStack(ModBlocks.MACHINE_FRAMES, 1, 0));
|
||||
}
|
||||
else {
|
||||
items.add(new ItemStack(this));
|
||||
drops.add(new ItemStack(this));
|
||||
}
|
||||
|
||||
return items;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -232,5 +232,4 @@ public abstract class BlockTransformer extends BaseTileBlock {
|
|||
return Iterators.forArray(this.facings());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -26,6 +26,8 @@ package techreborn.tiles;
|
|||
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.ITickable;
|
||||
|
@ -34,14 +36,52 @@ import net.minecraft.util.math.BlockPos;
|
|||
import net.minecraft.util.text.TextComponentString;
|
||||
import net.minecraft.util.text.TextFormatting;
|
||||
import net.minecraft.world.World;
|
||||
import reborncore.api.IToolDrop;
|
||||
import reborncore.common.util.ChatUtils;
|
||||
import techreborn.blocks.BlockAlarm;
|
||||
import techreborn.init.ModBlocks;
|
||||
import techreborn.init.ModSounds;
|
||||
import techreborn.lib.MessageIDs;
|
||||
|
||||
public class TileAlarm extends TileEntity implements ITickable {
|
||||
public class TileAlarm extends TileEntity
|
||||
implements ITickable, IToolDrop {
|
||||
private int selectedSound = 1;
|
||||
|
||||
public void rightClick() {
|
||||
if (!world.isRemote) {
|
||||
if (selectedSound < 3) {
|
||||
selectedSound++;
|
||||
} else {
|
||||
selectedSound = 1;
|
||||
}
|
||||
ChatUtils.sendNoSpamMessages(MessageIDs.alarmID, new TextComponentString(TextFormatting.GRAY + I18n.format("techreborn.message.alarm") + " " + "Alarm " + selectedSound));
|
||||
}
|
||||
}
|
||||
|
||||
// TileEntity
|
||||
@Override
|
||||
public NBTTagCompound writeToNBT(NBTTagCompound compound) {
|
||||
if (compound == null) {
|
||||
compound = new NBTTagCompound();
|
||||
}
|
||||
compound.setInteger("selectedSound", this.selectedSound);
|
||||
return super.writeToNBT(compound);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound compound) {
|
||||
if (compound != null && compound.hasKey("selectedSound")) {
|
||||
this.selectedSound = compound.getInteger("selectedSound");
|
||||
}
|
||||
super.readFromNBT(compound);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldRefresh(World world, BlockPos pos, IBlockState oldState, IBlockState newSate) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// ITickable
|
||||
@Override
|
||||
public void update() {
|
||||
if (!world.isRemote && world.getTotalWorldTime() % 25 == 0 && world.isBlockPowered(getPos())) {
|
||||
|
@ -63,36 +103,9 @@ public class TileAlarm extends TileEntity implements ITickable {
|
|||
}
|
||||
}
|
||||
|
||||
// IToolDrop
|
||||
@Override
|
||||
public NBTTagCompound writeToNBT(NBTTagCompound compound) {
|
||||
if (compound == null) {
|
||||
compound = new NBTTagCompound();
|
||||
}
|
||||
compound.setInteger("selectedSound", this.selectedSound);
|
||||
return super.writeToNBT(compound);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound compound) {
|
||||
if (compound != null && compound.hasKey("selectedSound")) {
|
||||
this.selectedSound = compound.getInteger("selectedSound");
|
||||
}
|
||||
super.readFromNBT(compound);
|
||||
}
|
||||
|
||||
public void rightClick() {
|
||||
if (!world.isRemote) {
|
||||
if (selectedSound < 3) {
|
||||
selectedSound++;
|
||||
} else {
|
||||
selectedSound = 1;
|
||||
}
|
||||
ChatUtils.sendNoSpamMessages(MessageIDs.alarmID, new TextComponentString(TextFormatting.GRAY + I18n.format("techreborn.message.alarm") + " " + "Alarm " + selectedSound));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldRefresh(World world, BlockPos pos, IBlockState oldState, IBlockState newSate) {
|
||||
return false;
|
||||
public ItemStack getToolDrop(final EntityPlayer entityPlayer) {
|
||||
return new ItemStack(ModBlocks.ALARM, 1);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,16 +26,20 @@ package techreborn.tiles.lighting;
|
|||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.ITickable;
|
||||
import reborncore.api.IToolDrop;
|
||||
import reborncore.common.powerSystem.TilePowerAcceptor;
|
||||
import techreborn.blocks.lighting.BlockLamp;
|
||||
import techreborn.init.ModBlocks;
|
||||
|
||||
public class TileLamp extends TilePowerAcceptor
|
||||
implements ITickable {
|
||||
public class TileLamp extends TilePowerAcceptor
|
||||
implements IToolDrop {
|
||||
|
||||
private static int capacity = 33;
|
||||
|
||||
// TilePowerAcceptor
|
||||
@Override
|
||||
public void update() {
|
||||
super.update();
|
||||
|
@ -81,5 +85,11 @@ public class TileLamp extends TilePowerAcceptor
|
|||
return 32;
|
||||
}
|
||||
|
||||
// IToolDrop
|
||||
@Override
|
||||
public ItemStack getToolDrop(final EntityPlayer entityPlayer) {
|
||||
return new ItemStack(ModBlocks.LAMP_LED, 1);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue