Small improvements to the cables
This commit is contained in:
parent
5203ad5b01
commit
3e5f02ab4e
3 changed files with 49 additions and 18 deletions
|
@ -33,6 +33,7 @@ import net.minecraft.block.state.BlockStateContainer;
|
|||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
@ -47,10 +48,12 @@ import net.minecraft.world.chunk.Chunk;
|
|||
import net.minecraftforge.energy.CapabilityEnergy;
|
||||
import techreborn.client.TechRebornCreativeTab;
|
||||
import techreborn.init.ModBlocks;
|
||||
import techreborn.items.tools.ItemWrench;
|
||||
import techreborn.tiles.cable.TileCable;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.security.InvalidParameterException;
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
* Created by modmuss50 on 19/05/2017.
|
||||
|
@ -81,6 +84,30 @@ public class BlockCable extends BlockContainer {
|
|||
throw new InvalidParameterException("The cable " + name + " could not be found.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
|
||||
ItemStack stack = playerIn.getHeldItem(hand);
|
||||
if(stack.getItem() instanceof ItemWrench && !world.isRemote){ //TODO use new api
|
||||
ItemStack itemStack = new ItemStack(this, 1, getMetaFromState(state));
|
||||
Random rand = new Random();
|
||||
|
||||
float dX = rand.nextFloat() * 0.8F + 0.1F;
|
||||
float dY = rand.nextFloat() * 0.8F + 0.1F;
|
||||
float dZ = rand.nextFloat() * 0.8F + 0.1F;
|
||||
|
||||
EntityItem entityItem = new EntityItem(world, pos.getX() + dX, pos.getY() + dY, pos.getZ() + dZ,
|
||||
itemStack.copy());
|
||||
|
||||
float factor = 0.05F;
|
||||
entityItem.motionX = rand.nextGaussian() * factor;
|
||||
entityItem.motionY = rand.nextGaussian() * factor + 0.2F;
|
||||
entityItem.motionZ = rand.nextGaussian() * factor;
|
||||
world.spawnEntity(entityItem);
|
||||
world.setBlockToAir(pos);
|
||||
}
|
||||
return super.onBlockActivated(world, pos, state, playerIn, hand, facing, hitX, hitY, hitZ);
|
||||
}
|
||||
|
||||
public static ItemStack getCableByName(String name) {
|
||||
return getCableByName(name, 1);
|
||||
}
|
||||
|
|
|
@ -72,7 +72,7 @@ public class ItemWrench extends ItemTR {
|
|||
public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos,
|
||||
EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
|
||||
if (!PermissionAPI.hasPermission(player.getGameProfile(), RebornPermissions.WRENCH_BLOCK, new BlockPosContext(player, pos, world.getBlockState(pos), facing))) {
|
||||
return EnumActionResult.FAIL;
|
||||
return EnumActionResult.PASS;
|
||||
}
|
||||
if (CompatManager.isIC2Loaded) {
|
||||
EnumActionResult result = IC2WrenchHelper.onItemUse(player.getHeldItem(hand), player, world, pos, hand, facing, hitX, hitY, hitZ);
|
||||
|
@ -81,11 +81,11 @@ public class ItemWrench extends ItemTR {
|
|||
}
|
||||
}
|
||||
if (world.isAirBlock(pos)) {
|
||||
return EnumActionResult.FAIL;
|
||||
return EnumActionResult.PASS;
|
||||
}
|
||||
TileEntity tile = world.getTileEntity(pos);
|
||||
if (tile == null) {
|
||||
return EnumActionResult.FAIL;
|
||||
return EnumActionResult.PASS;
|
||||
}
|
||||
if (!world.isRemote) {
|
||||
if (player.isSneaking()) {
|
||||
|
@ -151,9 +151,9 @@ public class ItemWrench extends ItemTR {
|
|||
|
||||
}
|
||||
}
|
||||
return EnumActionResult.FAIL;
|
||||
return EnumActionResult.PASS;
|
||||
} else {
|
||||
return EnumActionResult.FAIL;
|
||||
return EnumActionResult.PASS;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -35,17 +35,23 @@ import reborncore.common.RebornCoreConfig;
|
|||
import techreborn.blocks.cable.BlockCable;
|
||||
import techreborn.blocks.cable.EnumCableType;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by modmuss50 on 19/05/2017.
|
||||
*/
|
||||
public class TileCable extends TileEntity implements ITickable, IEnergyStorage {
|
||||
public int power = 0;
|
||||
|
||||
List<TileCable> sentTo = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
if (world.isRemote) {
|
||||
return;
|
||||
}
|
||||
sentTo.clear();
|
||||
for (EnumFacing face : EnumFacing.VALUES) {
|
||||
BlockPos offPos = getPos().offset(face);
|
||||
TileEntity tile = getWorld().getTileEntity(offPos);
|
||||
|
@ -53,25 +59,23 @@ public class TileCable extends TileEntity implements ITickable, IEnergyStorage {
|
|||
continue;
|
||||
}
|
||||
|
||||
if (!(tile instanceof TileCable) && tile.hasCapability(CapabilityEnergy.ENERGY, face.getOpposite())) {
|
||||
if (tile.hasCapability(CapabilityEnergy.ENERGY, face.getOpposite())) {
|
||||
if(tile instanceof TileCable){
|
||||
if (((TileCable) tile).sentTo.contains(this)){
|
||||
continue;
|
||||
}
|
||||
}
|
||||
IEnergyStorage energy = tile.getCapability(CapabilityEnergy.ENERGY, face.getOpposite());
|
||||
if (energy.canReceive()) {
|
||||
int move = energy.receiveEnergy(Math.min(getCableType().transferRate, power), false);
|
||||
if (move != 0) {
|
||||
if (move != 0 && power >= move) {
|
||||
power -= move;
|
||||
if(tile instanceof TileCable){
|
||||
sentTo.add((TileCable) tile);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (tile instanceof TileCable) {
|
||||
TileCable cable = (TileCable) tile;
|
||||
int averPower = (power + cable.power) / 2;
|
||||
cable.power = averPower;
|
||||
if (averPower % 2 != 0 && power != 0) {
|
||||
averPower++;
|
||||
}
|
||||
power = averPower;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -111,7 +115,7 @@ public class TileCable extends TileEntity implements ITickable, IEnergyStorage {
|
|||
|
||||
@Override
|
||||
public int getMaxEnergyStored() {
|
||||
return getCableType().transferRate * 2;
|
||||
return getCableType().transferRate;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in a new issue