Updated block wrenching

This commit is contained in:
drcrazy 2018-06-14 18:32:35 +03:00
parent 77e1c54b86
commit c409b67c3c
8 changed files with 151 additions and 112 deletions

View file

@ -45,7 +45,9 @@ 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.items.WrenchHelper;
import techreborn.client.TechRebornCreativeTab; import techreborn.client.TechRebornCreativeTab;
import techreborn.lib.ModInfo; import techreborn.lib.ModInfo;
import techreborn.tiles.TileAlarm; import techreborn.tiles.TileAlarm;
@ -88,19 +90,30 @@ public class BlockAlarm extends BaseTileBlock {
} }
@Override @Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) { public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn,
TileAlarm tileEntity = (TileAlarm) worldIn.getTileEntity(pos); 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) { if (tileEntity == null) {
return super.onBlockActivated(worldIn, pos, state, playerIn, hand, facing, hitX, hitY, hitZ); return false;
} else {
if (!worldIn.isRemote) {
if (playerIn.isSneaking()) {
tileEntity.rightClick();
}
}
} }
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 @Override
public int getMetaFromState(IBlockState state) { public int getMetaFromState(IBlockState state) {
@ -167,10 +180,10 @@ public class BlockAlarm extends BaseTileBlock {
} }
@Override @Override
public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos) { public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos) {
return this.bbs[getFacing(state).getIndex()]; return this.bbs[getFacing(state).getIndex()];
} }
@Override @Override
public void addInformation(final ItemStack stack, final World world, final List<String> tooltip, ITooltipFlag flag) { public void addInformation(final ItemStack stack, final World world, final List<String> tooltip, ITooltipFlag flag) {
tooltip.add(TextFormatting.GRAY + I18n.format("techreborn.tooltip.alarm")); tooltip.add(TextFormatting.GRAY + I18n.format("techreborn.tooltip.alarm"));

View file

@ -34,11 +34,14 @@ import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.NonNullList; 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 net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly; import net.minecraftforge.fml.relauncher.SideOnly;
import prospector.shootingstar.ShootingStar; import prospector.shootingstar.ShootingStar;
import prospector.shootingstar.model.ModelCompound; import prospector.shootingstar.model.ModelCompound;
import reborncore.common.RebornCoreConfig;
import reborncore.common.blocks.PropertyString; import reborncore.common.blocks.PropertyString;
import reborncore.common.multiblock.BlockMultiblockBase; import reborncore.common.multiblock.BlockMultiblockBase;
import reborncore.common.util.ArrayUtils; import reborncore.common.util.ArrayUtils;
@ -81,6 +84,33 @@ public class BlockMachineCasing extends BlockMultiblockBase {
return getStackByName(name, 1); 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 @Override
public IBlockState getStateFromMeta(int meta) { public IBlockState getStateFromMeta(int meta) {
if (meta > types.length) { if (meta > types.length) {
@ -99,23 +129,6 @@ public class BlockMachineCasing extends BlockMultiblockBase {
return new BlockStateContainer(this, TYPE); 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 @Override
public Item getItemDropped(IBlockState state, Random rand, int fortune) { public Item getItemDropped(IBlockState state, Random rand, int fortune) {
return Item.getItemFromBlock(this); return Item.getItemFromBlock(this);

View file

@ -78,6 +78,38 @@ public class BlockLamp extends BaseTileBlock {
ShootingStar.registerModel(new ModelCompound(ModInfo.MOD_ID, this, "machines/lighting")); 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 @Override
protected BlockStateContainer createBlockState() { protected BlockStateContainer createBlockState() {
FACING = PropertyDirection.create("facing"); FACING = PropertyDirection.create("facing");
@ -85,11 +117,6 @@ public class BlockLamp extends BaseTileBlock {
return new BlockStateContainer(this, FACING, ACTIVE); return new BlockStateContainer(this, FACING, ACTIVE);
} }
@Override
public TileEntity createNewTileEntity(final World world, final int meta) {
return new TileLamp();
}
@Override @Override
public IBlockState getStateForPlacement(World world, BlockPos pos, EnumFacing facing, float hitX, float hitY, public IBlockState getStateForPlacement(World world, BlockPos pos, EnumFacing facing, float hitX, float hitY,
float hitZ, int meta, EntityLivingBase placer, EnumHand hand) { float hitZ, int meta, EntityLivingBase placer, EnumHand hand) {
@ -148,29 +175,4 @@ public class BlockLamp extends BaseTileBlock {
EnumFacing facing = EnumFacing.getFront(meta&7); EnumFacing facing = EnumFacing.getFront(meta&7);
return this.getDefaultState().withProperty(FACING, facing).withProperty(ACTIVE, active); 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;
}
} }

View file

@ -27,6 +27,7 @@ package techreborn.blocks.transformers;
import net.minecraft.block.state.IBlockState; import net.minecraft.block.state.IBlockState;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.NonNullList;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess; import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World; import net.minecraft.world.World;
@ -34,9 +35,6 @@ import reborncore.common.RebornCoreConfig;
import techreborn.init.ModBlocks; import techreborn.init.ModBlocks;
import techreborn.tiles.transformers.TileHVTransformer; import techreborn.tiles.transformers.TileHVTransformer;
import java.util.ArrayList;
import java.util.List;
/** /**
* Created by modmuss50 on 16/03/2016. * 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) { public TileEntity createNewTileEntity(final World world, final int meta) {
return new TileHVTransformer(); 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>();
@Override
public void getDrops(NonNullList<ItemStack> drops, final IBlockAccess world, final BlockPos pos, final IBlockState state, final int fortune) {
if (RebornCoreConfig.wrenchRequired){ if (RebornCoreConfig.wrenchRequired){
items.add(new ItemStack(ModBlocks.MACHINE_FRAMES, 1, 1)); drops.add(new ItemStack(ModBlocks.MACHINE_FRAMES, 1, 1));
} }
else { else {
items.add(new ItemStack(this)); drops.add(new ItemStack(this));
} }
return items;
} }
} }

View file

@ -27,6 +27,7 @@ package techreborn.blocks.transformers;
import net.minecraft.block.state.IBlockState; import net.minecraft.block.state.IBlockState;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.NonNullList;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess; import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World; import net.minecraft.world.World;
@ -34,9 +35,6 @@ import reborncore.common.RebornCoreConfig;
import techreborn.init.ModBlocks; import techreborn.init.ModBlocks;
import techreborn.tiles.transformers.TileMVTransformer; import techreborn.tiles.transformers.TileMVTransformer;
import java.util.ArrayList;
import java.util.List;
/** /**
* Created by modmuss50 on 16/03/2016. * Created by modmuss50 on 16/03/2016.
*/ */
@ -52,16 +50,12 @@ public class BlockMVTransformer extends BlockTransformer {
} }
@Override @Override
public List<ItemStack> getDrops(final IBlockAccess world, final BlockPos pos, final IBlockState state, final int fortune) { public void getDrops(NonNullList<ItemStack> drops, final IBlockAccess world, final BlockPos pos, final IBlockState state, final int fortune) {
List<ItemStack> items = new ArrayList<ItemStack>();
if (RebornCoreConfig.wrenchRequired){ if (RebornCoreConfig.wrenchRequired){
items.add(new ItemStack(ModBlocks.MACHINE_FRAMES, 1, 0)); drops.add(new ItemStack(ModBlocks.MACHINE_FRAMES, 1, 0));
} }
else { else {
items.add(new ItemStack(this)); drops.add(new ItemStack(this));
} }
return items;
} }
} }

View file

@ -232,5 +232,4 @@ public abstract class BlockTransformer extends BaseTileBlock {
return Iterators.forArray(this.facings()); return Iterators.forArray(this.facings());
} }
} }
} }

View file

@ -26,6 +26,8 @@ package techreborn.tiles;
import net.minecraft.block.state.IBlockState; import net.minecraft.block.state.IBlockState;
import net.minecraft.client.resources.I18n; 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.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ITickable; 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.TextComponentString;
import net.minecraft.util.text.TextFormatting; import net.minecraft.util.text.TextFormatting;
import net.minecraft.world.World; import net.minecraft.world.World;
import reborncore.api.IToolDrop;
import reborncore.common.util.ChatUtils; import reborncore.common.util.ChatUtils;
import techreborn.blocks.BlockAlarm; import techreborn.blocks.BlockAlarm;
import techreborn.init.ModBlocks;
import techreborn.init.ModSounds; import techreborn.init.ModSounds;
import techreborn.lib.MessageIDs; import techreborn.lib.MessageIDs;
public class TileAlarm extends TileEntity implements ITickable { public class TileAlarm extends TileEntity
implements ITickable, IToolDrop {
private int selectedSound = 1; 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 @Override
public void update() { public void update() {
if (!world.isRemote && world.getTotalWorldTime() % 25 == 0 && world.isBlockPowered(getPos())) { if (!world.isRemote && world.getTotalWorldTime() % 25 == 0 && world.isBlockPowered(getPos())) {
@ -63,36 +103,9 @@ public class TileAlarm extends TileEntity implements ITickable {
} }
} }
// IToolDrop
@Override @Override
public NBTTagCompound writeToNBT(NBTTagCompound compound) { public ItemStack getToolDrop(final EntityPlayer entityPlayer) {
if (compound == null) { return new ItemStack(ModBlocks.ALARM, 1);
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;
} }
} }

View file

@ -26,16 +26,20 @@ package techreborn.tiles.lighting;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState; 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.EnumFacing;
import net.minecraft.util.ITickable; import reborncore.api.IToolDrop;
import reborncore.common.powerSystem.TilePowerAcceptor; import reborncore.common.powerSystem.TilePowerAcceptor;
import techreborn.blocks.lighting.BlockLamp; import techreborn.blocks.lighting.BlockLamp;
import techreborn.init.ModBlocks;
public class TileLamp extends TilePowerAcceptor public class TileLamp extends TilePowerAcceptor
implements ITickable { implements IToolDrop {
private static int capacity = 33; private static int capacity = 33;
// TilePowerAcceptor
@Override @Override
public void update() { public void update() {
super.update(); super.update();
@ -81,5 +85,11 @@ public class TileLamp extends TilePowerAcceptor
return 32; return 32;
} }
// IToolDrop
@Override
public ItemStack getToolDrop(final EntityPlayer entityPlayer) {
return new ItemStack(ModBlocks.LAMP_LED, 1);
}
} }