Increased slag brick recipe yield. Block Placer can plant Cocoa. Placer seed detection fixed (issue #64). Alternative fluid accumulator recipe enabling fixed. Small Solar Panel peak power decreased (too much compared to Thermo-electric Generator).

This commit is contained in:
stfwi 2019-11-17 21:41:27 +01:00
parent 1938f34faf
commit d159dbca8c
105 changed files with 1952 additions and 470 deletions

View file

@ -8,9 +8,6 @@
*/
package wile.engineersdecor.blocks;
import net.minecraft.block.BlockChest;
import net.minecraft.inventory.IInventory;
import net.minecraft.tileentity.TileEntityChest;
import wile.engineersdecor.ModEngineersDecor;
import net.minecraft.entity.passive.EntityCow;
import net.minecraft.init.SoundEvents;
@ -31,10 +28,10 @@ import net.minecraft.tileentity.TileEntity;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.init.Items;
import net.minecraft.item.*;
import net.minecraft.util.*;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.*;
import net.minecraftforge.common.capabilities.ICapabilityProvider;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.energy.CapabilityEnergy;
@ -42,6 +39,7 @@ import net.minecraftforge.energy.IEnergyStorage;
import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.items.ItemHandlerHelper;
import net.minecraftforge.items.wrapper.PlayerMainInvWrapper;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.FluidUtil;
import net.minecraftforge.fluids.FluidStack;
@ -49,11 +47,15 @@ import net.minecraftforge.fluids.capability.CapabilityFluidHandler;
import net.minecraftforge.fluids.capability.IFluidHandler;
import net.minecraftforge.fluids.capability.IFluidTankProperties;
import wile.engineersdecor.detail.ExtItems;
import wile.engineersdecor.detail.ItemHandling;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.List;
import java.util.Map.Entry;
import java.util.UUID;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class BlockDecorMilker extends BlockDecorDirectedHorizontal
@ -61,7 +63,6 @@ public class BlockDecorMilker extends BlockDecorDirectedHorizontal
public static final PropertyBool FILLED = PropertyBool.create("filled");
public static final PropertyBool ACTIVE = PropertyBool.create("active");
public BlockDecorMilker(@Nonnull String registryName, long config, @Nullable Material material, float hardness, float resistance, @Nullable SoundType sound, @Nonnull AxisAlignedBB unrotatedAABB)
{
super(registryName, config, material, hardness, resistance, sound, unrotatedAABB);
@ -144,15 +145,15 @@ public class BlockDecorMilker extends BlockDecorDirectedHorizontal
BTileEntity te = getTe(world, pos);
if(te==null) return true;
final ItemStack in_stack = player.getHeldItem(hand);
final ItemStack out_stack = te.milk_filled_container_item(in_stack);
final ItemStack out_stack = BTileEntity.milk_filled_container_item(in_stack);
if(out_stack.isEmpty()) return FluidUtil.interactWithFluidHandler(player, hand, te.fluid_handler());
boolean drained = false;
IItemHandler player_inventory = new PlayerMainInvWrapper(player.inventory);
if(te.fluid_level() >= 1000) {
if(te.fluid_level() >= BTileEntity.BUCKET_SIZE) {
final ItemStack insert_stack = out_stack.copy();
ItemStack remainder = ItemHandlerHelper.insertItemStacked(player_inventory, insert_stack, false);
if(remainder.getCount() < insert_stack.getCount()) {
te.drain(1000);
te.drain(BTileEntity.BUCKET_SIZE);
in_stack.shrink(1);
drained = true;
if(remainder.getCount() > 0) {
@ -180,18 +181,20 @@ public class BlockDecorMilker extends BlockDecorDirectedHorizontal
public static class BTileEntity extends TileEntity implements ITickable, ICapabilityProvider, IEnergyStorage
{
public static final int BUCKET_SIZE = 1000;
public static final int TICK_INTERVAL = 80;
public static final int PROCESSING_TICK_INTERVAL = 10;
public static final int TANK_CAPACITY = 12000;
public static final int PROCESSING_TICK_INTERVAL = 20;
public static final int TANK_CAPACITY = BUCKET_SIZE * 12;
public static final int MAX_MILKING_TANK_LEVEL = TANK_CAPACITY-500;
public static final int FILLED_INDICATION_THRESHOLD = BUCKET_SIZE;
public static final int MAX_ENERGY_BUFFER = 16000;
public static final int MAX_ENERGY_TRANSFER = 512;
public static final int DEFAULT_ENERGY_CONSUMPTION = 16;
public static final int DEFAULT_ENERGY_CONSUMPTION = 0;
private static final EnumFacing FLUID_TRANSFER_DIRECTRIONS[] = {EnumFacing.DOWN,EnumFacing.EAST,EnumFacing.SOUTH,EnumFacing.WEST,EnumFacing.NORTH};
private static final ItemStack BUCKET_STACK = new ItemStack(Items.BUCKET);
private enum MilkingState { IDLE, PICKED, COMING, POSITIONING, MILKING, LEAVING, WAITING }
private static FluidStack milk_fluid_ = new FluidStack(FluidRegistry.WATER, 0);
private static HashMap<ItemStack, ItemStack> milk_containers_ = new HashMap<>();
private static int energy_consumption = DEFAULT_ENERGY_CONSUMPTION;
private int tick_timer_;
private int energy_stored_;
@ -202,10 +205,22 @@ public class BlockDecorMilker extends BlockDecorDirectedHorizontal
private int state_timer_ = 0;
private BlockPos tracked_cow_original_position_ = null;
public static void on_config(int energy_consumption_per_tick, int heatup_per_second)
public static void on_config(int energy_consumption_per_tick)
{
energy_consumption = MathHelper.clamp(energy_consumption_per_tick, 0, 4096);
ModEngineersDecor.logger.info("Config milker energy consumption:" + energy_consumption + "rf/t");
energy_consumption = MathHelper.clamp(energy_consumption_per_tick, 0, 128);
{
Fluid milk = FluidRegistry.getFluid("milk");
if(milk != null) milk_fluid_ = new FluidStack(milk, BUCKET_SIZE);
}
{
milk_containers_.put(new ItemStack(Items.BUCKET), new ItemStack(Items.MILK_BUCKET));
if(ExtItems.BOTTLED_MILK_BOTTLE_DRINKLABLE!=null) milk_containers_.put(new ItemStack(Items.GLASS_BOTTLE), new ItemStack(ExtItems.BOTTLED_MILK_BOTTLE_DRINKLABLE));
}
ModEngineersDecor.logger.info(
"Config milker energy consumption:" + energy_consumption + "rf/t"
+ ((milk_fluid_==null)?"":" [milk fluid available]")
+ ((ExtItems.BOTTLED_MILK_BOTTLE_DRINKLABLE==null)?"":" [bottledmilk mod available]")
);
}
public BTileEntity()
@ -250,7 +265,7 @@ public class BlockDecorMilker extends BlockDecorDirectedHorizontal
{ return MathHelper.clamp(tank_level_, 0, TANK_CAPACITY); }
private void drain(int amount)
{ tank_level_ = MathHelper.clamp(tank_level_-1000, 0, TANK_CAPACITY); markDirty(); }
{ tank_level_ = MathHelper.clamp(tank_level_-BUCKET_SIZE, 0, TANK_CAPACITY); markDirty(); }
// TileEntity ------------------------------------------------------------------------------
@ -356,41 +371,39 @@ public class BlockDecorMilker extends BlockDecorDirectedHorizontal
// ITickable ------------------------------------------------------------------------------------
private void log(String s)
{} // may be enabled with config
{} // may be enabled with config, for dev was println
private ItemStack milk_filled_container_item(ItemStack stack)
{
// Returns out stack for input stack size == 1 (convert one item of the stack).
if(stack.isItemEqualIgnoreDurability(BTileEntity.BUCKET_STACK)) return new ItemStack(Items.MILK_BUCKET);
if((ExtItems.BOTTLED_MILK_BOTTLE_DRINKLABLE!=null) && stack.getItem().equals(Items.GLASS_BOTTLE)) return new ItemStack(ExtItems.BOTTLED_MILK_BOTTLE_DRINKLABLE);
return ItemStack.EMPTY;
}
private static ItemStack milk_filled_container_item(ItemStack stack)
{ return milk_containers_.entrySet().stream().filter(e->e.getKey().isItemEqual(stack)).map(Map.Entry::getValue).findFirst().orElse(ItemStack.EMPTY); }
private void fill_adjacent_inventory_item_containers(EnumFacing block_facing)
{
// Check inventory existence, back to down if possible, otherwise sort back into same inventory.
IInventory src, dst;
{
TileEntity te_src = world.getTileEntity(pos.offset(block_facing));
TileEntity te_dst = world.getTileEntity(pos.down());
if(!(te_src instanceof IInventory)) te_src = null;
if(!(te_dst instanceof IInventory)) te_dst = null;
if((te_src==null)) te_src = te_dst;
if((te_dst==null)) te_dst = te_src;
if((te_src==null) || (te_dst==null)) return;
src = (IInventory)te_src;
dst = (IInventory)te_dst;
// Check inventory existence, back to down is preferred, otherwise sort back into same inventory.
IItemHandler src = ItemHandling.itemhandler(world, pos.offset(block_facing), block_facing.getOpposite());
IItemHandler dst = ItemHandling.itemhandler(world, pos.down(), EnumFacing.UP);
if(src==null) { src = dst; } else if(dst==null) { dst = src; }
if((src==null) || (dst==null)) return;
while((tank_level_ >= BUCKET_SIZE)) {
boolean inserted = false;
for(Entry<ItemStack,ItemStack> e:milk_containers_.entrySet()) {
if(ItemHandling.extract(src, e.getKey(), 1, true).isEmpty()) continue;
if(!ItemHandling.insert(dst, e.getValue().copy(), false).isEmpty()) continue;
ItemHandling.extract(src, e.getKey(), 1, false);
tank_level_ -= BUCKET_SIZE;
inserted = true;
}
if(!inserted) break;
}
/// @todo --> hier weitermachen
}
private boolean milking_process()
{
if((tracked_cow_ == null) && (fluid_level() >= MAX_MILKING_TANK_LEVEL)) return false; // nothing to do
final EnumFacing facing = world.getBlockState(getPos()).getValue(FACING).getOpposite();
EntityCow cow = null;
{
final List<EntityCow> cows = world.getEntitiesWithinAABB(EntityCow.class, new AxisAlignedBB(pos).grow(16, 3, 16),
AxisAlignedBB aabb = new AxisAlignedBB(pos.offset(facing, 3)).grow(4, 2, 4);
final List<EntityCow> cows = world.getEntitiesWithinAABB(EntityCow.class, aabb,
e->(((tracked_cow_==null) && (!e.isChild() && !e.isInLove()))||(e.getPersistentID().equals(tracked_cow_)))
);
if(cows.size() == 1) {
@ -403,42 +416,43 @@ public class BlockDecorMilker extends BlockDecorDirectedHorizontal
if((cow == null) || (cow.isDead) || ((tracked_cow_ != null) && (!tracked_cow_.equals(cow.getPersistentID())))) { tracked_cow_ = null; cow = null; }
if(tracked_cow_ == null) state_ = MilkingState.IDLE;
if(cow == null) return false; // retry next cycle
final EnumFacing facing = world.getBlockState(getPos()).getValue(FACING).getOpposite();
tick_timer_ = PROCESSING_TICK_INTERVAL;
state_timer_ -= PROCESSING_TICK_INTERVAL;
if(state_timer_ > 0) return false;
switch(state_) {
switch(state_) { // Let's do this the old school FSA sequencing way ...
case IDLE: {
final List<EntityLivingBase> blocking_entities = world.getEntitiesWithinAABB(EntityLivingBase.class, new AxisAlignedBB(pos).grow(1, 2, 1));
if(blocking_entities.size() > 0) return false; // an entity is blocking the way
final List<EntityLivingBase> blocking_entities = world.getEntitiesWithinAABB(EntityLivingBase.class, new AxisAlignedBB(pos.offset(facing)).grow(0.5, 0.5, 0.5));
if(blocking_entities.size() > 0) { tick_timer_ = TICK_INTERVAL; return false; } // an entity is blocking the way
if(cow.getLeashed() || cow.isChild() || cow.isInLove() || (!cow.onGround) || cow.isBeingRidden() || cow.isSprinting()) return false;
tracked_cow_ = cow.getPersistentID();
state_ = MilkingState.PICKED;
state_timeout_ = 200;
tracked_cow_original_position_ = cow.getPosition();
log("Idle: Picked cow" + tracked_cow_);
return true;
return false;
}
case PICKED: {
if(cow.hasPath()) return true;
if(cow.hasPath()) return false;
BlockPos p = getPos().offset(facing).offset(facing.rotateY());
if(!cow.getNavigator().tryMoveToXYZ(p.getX(), p.getY(), p.getZ(),1.0)) {
log("Picked: No path");
tracked_cow_ = null;
tick_timer_ = TICK_INTERVAL;
return false;
}
state_ = MilkingState.COMING;
state_timeout_ = 300; // 15s should be enough
log("Picked: coming");
return true;
return false;
}
case COMING: {
BlockPos p = getPos().offset(facing).offset(facing.rotateY());
if(cow.getPosition().distanceSq(p) > 1) {
if(cow.hasPath()) return true;
if(cow.hasPath()) return false;
if(!cow.getNavigator().tryMoveToXYZ(p.getX(), p.getY(), p.getZ(),1.0)) {
log("Coming: lost path");
tracked_cow_ = null;
tick_timer_ = TICK_INTERVAL;
return false;
} else {
state_timeout_ -= 100;
@ -448,22 +462,24 @@ public class BlockDecorMilker extends BlockDecorDirectedHorizontal
if(!cow.getNavigator().tryMoveToXYZ(next_p.getX(), next_p.getY(), next_p.getZ(), 1.0)) {
log("Coming: No path");
tracked_cow_ = null;
tick_timer_ = TICK_INTERVAL;
return false;
}
log("Coming: position reached");
state_ = MilkingState.POSITIONING;
state_timeout_ = 100; // 5s
}
return true;
return false;
}
case POSITIONING: {
BlockPos p = getPos().offset(facing);
if(cow.getPosition().distanceSq(p) > 0) {
if(cow.hasPath()) return true;
if(p.distanceSqToCenter(cow.posX, cow.posY, cow.posZ) > 0.45) {
if(cow.hasPath()) return false;
if(!cow.getNavigator().tryMoveToXYZ(p.getX(), p.getY(), p.getZ(), 1.0)) {
log("Positioning: lost path");
tick_timer_ = TICK_INTERVAL;
} else {
state_timeout_ -= 200;
state_timeout_ -= 25;
}
tracked_cow_ = null;
return false;
@ -475,10 +491,10 @@ public class BlockDecorMilker extends BlockDecorDirectedHorizontal
state_ = MilkingState.MILKING;
state_timer_ = 30;
log("Positioning: start milking");
return true;
return false;
}
case MILKING: {
tank_level_ = MathHelper.clamp(tank_level_+1000, 0, TANK_CAPACITY);
tank_level_ = MathHelper.clamp(tank_level_+BUCKET_SIZE, 0, TANK_CAPACITY);
state_timeout_ = 600;
state_ = MilkingState.LEAVING;
state_timer_ = 20;
@ -493,15 +509,18 @@ public class BlockDecorMilker extends BlockDecorDirectedHorizontal
cow.getNavigator().tryMoveToXYZ(p.getX(), p.getY(), p.getZ(), 1.0);
state_timeout_ = 600;
state_timer_ = 500;
tick_timer_ = TICK_INTERVAL;
state_ = MilkingState.WAITING;
log("Leaving: process done");
return true;
}
case WAITING: {
tick_timer_ = TICK_INTERVAL;
return true; // wait for the timeout to kick in until starting with the next.
}
default:
default: {
tracked_cow_ = null;
}
}
return (tracked_cow_ != null);
}
@ -513,16 +532,20 @@ public class BlockDecorMilker extends BlockDecorDirectedHorizontal
tick_timer_ = TICK_INTERVAL;
final IBlockState block_state = world.getBlockState(pos);
boolean dirty = false;
if(energy_consumption > 0) {
if(energy_stored_ <= 0) return;
energy_stored_ = MathHelper.clamp(energy_stored_-energy_consumption, 0, MAX_ENERGY_BUFFER);
}
// Track and milk cows
if(milking_process()) dirty = true;
// Fluid transfer
if((milk_fluid_.amount > 0) && (fluid_level() >= 1000)) {
if((milk_fluid_.amount > 0) && (fluid_level() >= BUCKET_SIZE)) {
for(EnumFacing facing: FLUID_TRANSFER_DIRECTRIONS) {
IFluidHandler fh = FluidUtil.getFluidHandler(world, pos.offset(facing), facing.getOpposite());
if(fh == null) continue;
FluidStack fs = milk_fluid_.copy();
fs.amount = 1000;
int nfilled = MathHelper.clamp(fh.fill(fs, true), 0, 1000);
fs.amount = BUCKET_SIZE;
int nfilled = MathHelper.clamp(fh.fill(fs, true), 0, BUCKET_SIZE);
if(nfilled <= 0) continue;
tank_level_ -= nfilled;
if(tank_level_ < 0) tank_level_ = 0;
@ -531,11 +554,11 @@ public class BlockDecorMilker extends BlockDecorDirectedHorizontal
}
}
// Adjacent inventory update, only done just after milking to prevent waste of server cpu.
if(dirty && (fluid_level() >= 1000)) {
if(dirty && (fluid_level() >= BUCKET_SIZE)) {
fill_adjacent_inventory_item_containers(block_state.getValue(FACING));
}
// State update
IBlockState new_state = block_state.withProperty(FILLED, fluid_level()>0).withProperty(ACTIVE, state_==MilkingState.MILKING);
IBlockState new_state = block_state.withProperty(FILLED, fluid_level()>=FILLED_INDICATION_THRESHOLD).withProperty(ACTIVE, state_==MilkingState.MILKING);
if(block_state != new_state) world.setBlockState(pos, new_state,1|2|16);
if(dirty) markDirty();
}

View file

@ -11,10 +11,10 @@ package wile.engineersdecor.blocks;
import wile.engineersdecor.ModEngineersDecor;
import wile.engineersdecor.detail.Networking;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.init.SoundEvents;
import net.minecraft.world.IBlockAccess;
import net.minecraft.block.Block;
import net.minecraft.block.SoundType;
import net.minecraft.block.*;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.block.state.BlockFaceShape;
@ -46,6 +46,8 @@ import net.minecraftforge.fml.relauncher.SideOnly;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map.Entry;
public class BlockDecorPlacer extends BlockDecorDirected
@ -339,13 +341,14 @@ public class BlockDecorPlacer extends BlockDecorDirected
public static class BTileEntity extends TileEntity implements ITickable, ISidedInventory, Networking.IPacketReceiver
{
@FunctionalInterface private interface SpecialPlacementFunction{ EnumActionResult apply(ItemStack stack, World world, BlockPos pos);}
public static final int TICK_INTERVAL = 40;
public static final int NUM_OF_SLOTS = 18;
///
public static final int LOGIC_INVERTED = 0x01;
public static final int LOGIC_CONTINUOUS = 0x02;
public static final int DEFAULT_LOGIC = LOGIC_INVERTED|LOGIC_CONTINUOUS;
public static HashMap<ItemStack, SpecialPlacementFunction> special_placement_conversions = new HashMap<>();
///
private boolean block_power_signal_ = false;
private boolean block_power_updated_ = false;
@ -354,9 +357,21 @@ public class BlockDecorPlacer extends BlockDecorDirected
private int tick_timer_ = 0;
protected NonNullList<ItemStack> stacks_;
public static void on_config(int cooldown_ticks)
public static void on_config()
{
// ModEngineersDecor.logger.info("Config factory placer:");
special_placement_conversions.put(new ItemStack(Items.DYE, 1, 3), (stack,world,pos)->{ // cocoa
if(world.getBlockState(pos).getBlock() instanceof BlockCocoa) return EnumActionResult.PASS;
if(!Blocks.COCOA.canPlaceBlockAt(world, pos)) return EnumActionResult.FAIL;
for(EnumFacing facing:EnumFacing.HORIZONTALS) {
IBlockState st = world.getBlockState(pos.offset(facing));
if(!(st.getBlock() instanceof BlockLog)) continue;
if(st.getBlock().getMetaFromState(st) != 3) continue;
IBlockState state = Blocks.COCOA.getDefaultState().withProperty(BlockCocoa.FACING, facing);
return world.setBlockState(pos, state, 1|2) ? EnumActionResult.SUCCESS : EnumActionResult.FAIL;
}
return EnumActionResult.FAIL;
});
ModEngineersDecor.logger.info("Config placer: " + special_placement_conversions.size() + " special placement handling entries.");
}
public BTileEntity()
@ -589,29 +604,47 @@ public class BlockDecorPlacer extends BlockDecorDirected
private static boolean place_item(ItemStack stack, EntityPlayer placer, World world, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
{
if((stack.isEmpty()) || (!(stack.getItem() instanceof ItemBlock))) return false;
ItemBlock item = (ItemBlock)(stack.getItem());
final Item place_item = stack.getItem();
Block place_block = (place_item instanceof IPlantable) ? (((IPlantable)place_item).getPlant(world, pos)).getBlock() : Block.getBlockFromItem(place_item);
if(((place_block==Blocks.AIR) || (place_block==null)) && ((place_item instanceof ItemBlockSpecial) && (((ItemBlockSpecial)place_item).getBlock()!=null))) place_block = ((ItemBlockSpecial)place_item).getBlock(); // Covers e.g. REEDS
if((place_block==null) || (place_block==Blocks.AIR)) return false;
Block block = world.getBlockState(pos).getBlock();
if(!block.isReplaceable(world, pos)) pos = pos.offset(facing);
if(!world.mayPlace(item.getBlock(), pos, true, facing, (Entity)null)) return false;
int meta = item.getMetadata(stack.getMetadata());
final IBlockState state = item.getBlock().getStateForPlacement(world, pos, facing, hitX, hitY, hitZ, meta, placer, hand);
if(!item.placeBlockAt(stack, placer, world, pos, facing, hitX, hitY, hitZ, state)) return false;
if(!world.mayPlace(place_block, pos, true, facing, (Entity)null)) return false;
if(place_item instanceof ItemBlock) {
ItemBlock item = (ItemBlock)place_item;
int meta = item.getMetadata(stack.getMetadata());
final IBlockState state = item.getBlock().getStateForPlacement(world, pos, facing, hitX, hitY, hitZ, meta, placer, hand);
if(!item.placeBlockAt(stack, placer, world, pos, facing, hitX, hitY, hitZ, state)) return false;
} else if(place_item instanceof IPlantable) {
IPlantable item = (IPlantable)place_item;
final IBlockState state = item.getPlant(world, pos);
if(!world.setBlockState(pos, state, 1|2)) return false;
} else {
final IBlockState state = place_block.getDefaultState();
if(!world.setBlockState(pos, state, 1|2)) return false;
}
final IBlockState soundstate = world.getBlockState(pos);
final SoundType stype = soundstate.getBlock().getSoundType(soundstate, world, pos, placer);
world.playSound(placer, pos, stype.getPlaceSound(), SoundCategory.BLOCKS, (stype.getVolume()+1f)/8, stype.getPitch()*1.1f);
return true;
}
private boolean try_plant(BlockPos pos, final EnumFacing facing, final ItemStack stack, final Block block)
private boolean try_plant(BlockPos pos, final EnumFacing facing, final ItemStack stack, final Block plant_block)
{
Item item = stack.getItem();
final Item item = stack.getItem();
if((!(item instanceof ItemBlock)) && (!(item instanceof IPlantable)) && (!(plant_block instanceof IPlantable))) return spit_out(facing);
Block block = (plant_block instanceof IPlantable) ? plant_block : ((item instanceof IPlantable) ? (((IPlantable)item).getPlant(world, pos)).getBlock() : Block.getBlockFromItem(item));
if(item instanceof IPlantable) {
IBlockState st = ((IPlantable)item).getPlant(world, pos); // prefer block from getPlant
if(st!=null) block = st.getBlock();
}
if(world.isAirBlock(pos)) {
// plant here, block below has to be valid soil.
final IBlockState soilstate = world.getBlockState(pos.down());
if(!soilstate.getBlock().canSustainPlant(soilstate, world, pos.down(), EnumFacing.UP, (IPlantable)block)) {
if((block instanceof IPlantable) && (!soilstate.getBlock().canSustainPlant(soilstate, world, pos.down(), EnumFacing.UP, (IPlantable)block))) {
// Not the right soil for this plant.
return spit_out(facing);
return false;
}
} else {
// adjacent block is the soil, plant above if the soil is valid.
@ -622,9 +655,9 @@ public class BlockDecorPlacer extends BlockDecorDirected
} else if(!world.isAirBlock(pos.up())) {
// If this is the soil an air block is needed above, if that is blocked we can't plant.
return false;
} else if(!soilstate.getBlock().canSustainPlant(soilstate, world, pos, EnumFacing.UP, (IPlantable)block)) {
} else if((block instanceof IPlantable) && (!soilstate.getBlock().canSustainPlant(soilstate, world, pos, EnumFacing.UP, (IPlantable)block))) {
// Would be space above, but it's not the right soil for the plant.
return spit_out(facing);
return false;
} else {
// Ok, plant above.
pos = pos.up();
@ -658,39 +691,54 @@ public class BlockDecorPlacer extends BlockDecorDirected
}
if(current_stack.isEmpty()) { current_slot_index_ = 0; return false; }
final Item item = current_stack.getItem();
final Block block = Block.getBlockFromItem(item);
if(block == Blocks.AIR) return (item!=null) && spit_out(facing); // Item not accepted
if(world.getEntitiesWithinAABB(EntityLivingBase.class, new AxisAlignedBB(placement_pos)).size() > 0) {
return false;
}
if((block instanceof IPlantable) || (item instanceof IPlantable)) try_plant(placement_pos, facing, current_stack, block);
if(world.getBlockState(placement_pos).getBlock().isReplaceable(world, placement_pos)) {
if(item instanceof ItemBlock) {
try {
final FakePlayer placer = net.minecraftforge.common.util.FakePlayerFactory.getMinecraft((net.minecraft.world.WorldServer)world);
//println("PLACE ITEMBLOCK" + current_stack + " --> " + block + " at " + placement_pos.subtract(pos) + "( item=" + item + ")");
ItemStack placement_stack = current_stack.copy();
placement_stack.setCount(1);
if((placer==null) || (!place_item(placement_stack, placer, world, placement_pos, EnumHand.MAIN_HAND, EnumFacing.DOWN, 0.6f, 0f, 0.5f))) return spit_out(facing);
current_stack.shrink(1);
stacks_.set(current_slot_index_, current_stack);
return true;
} catch(Throwable e) {
// The block really needs a player or other issues happened during placement.
// A hard crash should not be fired here, instead spit out the item to indicated that this
// block is not compatible.
ModEngineersDecor.logger.error("Exception while trying to place " + e);
world.setBlockToAir(placement_pos);
return spit_out(facing);
Block block = Block.getBlockFromItem(item);
if(((block==Blocks.AIR) || (block==null)) && ((item instanceof ItemBlockSpecial) && (((ItemBlockSpecial)item).getBlock()!=null))) block = ((ItemBlockSpecial)item).getBlock(); // e.g. reeds
if(item == null) return false;
if((item instanceof IPlantable) || (block instanceof IPlantable)) return try_plant(placement_pos, facing, current_stack, block);
if(block == Blocks.AIR) {
// Check special stuff that is not detected otherwise (like coco, which is technically dye)
try {
for(Entry<ItemStack,SpecialPlacementFunction> e:special_placement_conversions.entrySet()) {
if(e.getKey().isItemEqual(current_stack)) {
ItemStack placement_stack = current_stack.copy();
placement_stack.setCount(1);
switch(e.getValue().apply(current_stack, world, placement_pos)) {
case PASS:
return false;
case SUCCESS:
current_stack.shrink(1);
stacks_.set(current_slot_index_, current_stack);
return true;
default:
return false;
}
}
}
} else {
// No idea if this is a particulary good idea, as getBlockFromITem
//println("SPIT NON ITEMBLOCK" + current_stack + " --> " + block + " at " + placement_pos.subtract(pos) + "( item=" + item + ")");
return spit_out(facing);
} catch(Throwable e) {
ModEngineersDecor.logger.error("Exception while trying to place " + e);
world.setBlockToAir(placement_pos);
}
return spit_out(facing);
}
return false;
if(world.getEntitiesWithinAABB(EntityLivingBase.class, new AxisAlignedBB(placement_pos)).size() > 0) return false;
if(!world.getBlockState(placement_pos).getBlock().isReplaceable(world, placement_pos)) return false;
try {
final FakePlayer placer = net.minecraftforge.common.util.FakePlayerFactory.getMinecraft((net.minecraft.world.WorldServer)world);
//println("PLACE ITEMBLOCK" + current_stack + " --> " + block + " at " + placement_pos.subtract(pos) + "( item=" + item + ")");
ItemStack placement_stack = current_stack.copy();
placement_stack.setCount(1);
if((placer==null) || (!place_item(placement_stack, placer, world, placement_pos, EnumHand.MAIN_HAND, EnumFacing.DOWN, 0.6f, 0f, 0.5f))) return false;
current_stack.shrink(1);
stacks_.set(current_slot_index_, current_stack);
} catch(Throwable e) {
// The block really needs a player or other issues happened during placement.
// A hard crash should not be fired here, instead spit out the item to indicated that this
// block is not compatible.
ModEngineersDecor.logger.error("Exception while trying to place " + e);
world.setBlockToAir(placement_pos);
return spit_out(facing);
}
return true;
}
@Override
@ -715,7 +763,13 @@ public class BlockDecorPlacer extends BlockDecorDirected
if(block_power_updated_) dirty = true;
}
// Placing
if(trigger && try_place(placer_facing)) dirty = true;
if(trigger) {
if(try_place(placer_facing)) {
dirty = true;
} else {
current_slot_index_ = next_slot(current_slot_index_);
}
}
if(dirty) markDirty();
if(trigger && (tick_timer_ > TICK_INTERVAL)) tick_timer_ = TICK_INTERVAL;
}

View file

@ -99,7 +99,7 @@ public class BlockDecorSolarPanel extends BlockDecor
public static class BTileEntity extends TileEntity implements ITickable
{
public static final int DEFAULT_PEAK_POWER = 45;
public static final int DEFAULT_PEAK_POWER = 32;
public static final int TICK_INTERVAL = 8;
public static final int ACCUMULATION_INTERVAL = 4;
private static final EnumFacing transfer_directions_[] = {EnumFacing.DOWN, EnumFacing.EAST, EnumFacing.SOUTH, EnumFacing.WEST, EnumFacing.NORTH };

View file

@ -0,0 +1,70 @@
package wile.engineersdecor.detail;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.ISidedInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.items.CapabilityItemHandler;
import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.items.ItemHandlerHelper;
import net.minecraftforge.items.wrapper.InvWrapper;
import net.minecraftforge.items.wrapper.SidedInvWrapper;
import javax.annotation.Nullable;
public class ItemHandling
{
public static IItemHandler itemhandler(World world, BlockPos pos, @Nullable EnumFacing side)
{
TileEntity te = world.getTileEntity(pos);
if(te==null) return null;
if(te.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, side)) return (IItemHandler)te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, side);
if((side!=null) && (te instanceof ISidedInventory)) return new SidedInvWrapper((ISidedInventory)te, side);
if(te instanceof IInventory) return new InvWrapper((IInventory)te);
return null;
}
public static ItemStack insert(IItemHandler inventory, ItemStack stack , boolean simulate)
{ return ItemHandlerHelper.insertItemStacked(inventory, stack, simulate); }
public static ItemStack insert(TileEntity te, @Nullable EnumFacing side, ItemStack stack, boolean simulate)
{
if(te==null) return stack;
IItemHandler hnd = null;
if(te.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, side)) {
hnd = (IItemHandler)te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, side);
} else if((side!=null) && (te instanceof ISidedInventory)) {
hnd = new SidedInvWrapper((ISidedInventory)te, side);
} else if(te instanceof IInventory) {
hnd = new InvWrapper((IInventory)te);
}
return (hnd==null) ? stack : ItemHandlerHelper.insertItemStacked(hnd, stack, simulate);
}
public static ItemStack extract(IItemHandler inventory, @Nullable ItemStack match, int amount, boolean simulate)
{
if((inventory==null) || (amount<=0)) return ItemStack.EMPTY;
final int max = inventory.getSlots();
ItemStack out_stack = ItemStack.EMPTY;
for(int i=0; i<max; ++i) {
final ItemStack stack = inventory.getStackInSlot(i);
if(stack.isEmpty()) continue;
if(out_stack.isEmpty()) {
if((match!=null) && (!stack.isItemEqual(match))) continue;
out_stack = inventory.extractItem(i, amount, simulate);
} else if(stack.isItemEqual(out_stack)) {
ItemStack es = inventory.extractItem(i, (amount-out_stack.getCount()), simulate);
out_stack.grow(es.getCount());
}
if(out_stack.getCount() >= amount) break;
}
return out_stack;
}
}

View file

@ -21,6 +21,7 @@ import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.client.event.ConfigChangedEvent;
import wile.engineersdecor.blocks.BlockDecorMilker.BTileEntity;
import javax.annotation.Nullable;
import java.util.ArrayList;
@ -434,6 +435,16 @@ public class ModConfig
})
@Config.Name("Tree Cutter: Power required")
public boolean tree_cuttter_requires_power = false;
@Config.Comment({
"Defines how much RF power the milking machine needs to work. Note this is a permanent " +
"standby consumption (not only when the machine does something). If zero, the machine " +
"does not need power at all to function." +
"The config value can be changed on-the-fly for tuning."
})
@Config.Name("Milker: Power consumption")
@Config.RangeInt(min=0, max=128)
public int milker_energy_consumption = BTileEntity.DEFAULT_ENERGY_CONSUMPTION;
}
@SuppressWarnings("unused")
@ -450,11 +461,14 @@ public class ModConfig
@SuppressWarnings("unused")
public static final void onPreInit()
{ apply(); }
{ startup_apply(); }
@SuppressWarnings("unused")
public static final void onPostInit(FMLPostInitializationEvent event)
{ for(Block e: ModContent.getRegisteredBlocks()) ModConfig.isOptedOut(e, true); }
{
for(Block e: ModContent.getRegisteredBlocks()) ModConfig.isOptedOut(e, true);
apply();
}
private static final ArrayList<String> includes_ = new ArrayList<String>();
private static final ArrayList<String> excludes_ = new ArrayList<String>();
@ -549,19 +563,10 @@ public class ModConfig
return false;
}
public static final void apply()
public static final void startup_apply()
{
BlockDecorFurnace.BTileEntity.on_config(tweaks.furnace_smelting_speed_percent, tweaks.furnace_fuel_efficiency_percent, tweaks.furnace_boost_energy_consumption);
ModRecipes.furnaceRecipeOverrideReset();
if(tweaks.furnace_smelts_nuggets) ModRecipes.furnaceRecipeOverrideSmeltsOresToNuggets();
BlockDecorChair.on_config(optout.without_chair_sitting, optout.without_mob_chair_sitting, tweaks.chair_mob_sitting_probability_percent, tweaks.chair_mob_standup_probability_percent);
BlockDecorLadder.on_config(optout.without_ladder_speed_boost);
BlockDecorCraftingTable.on_config(optout.without_crafting_table_history, false, tweaks.with_crafting_quickmove_buttons);
BlockDecorPipeValve.on_config(tweaks.pipevalve_max_flowrate, tweaks.pipevalve_redstone_slope);
BlockDecorFurnaceElectrical.BTileEntity.on_config(tweaks.e_furnace_speed_percent, tweaks.e_furnace_power_consumption);
BlockDecorSolarPanel.BTileEntity.on_config(tweaks.solar_panel_peak_power);
BlockDecorBreaker.BTileEntity.on_config(tweaks.block_breaker_power_consumption, tweaks.block_breaker_reluctance, tweaks.block_breaker_min_breaking_time, tweaks.block_breaker_requires_power);
BlockDecorTreeCutter.BTileEntity.on_config(tweaks.tree_cuttter_energy_consumption, tweaks.tree_cuttter_cutting_time_needed, tweaks.tree_cuttter_requires_power);
{
optout.includes = optout.includes.toLowerCase().replaceAll(ModEngineersDecor.MODID+":", "").replaceAll("[^*_,a-z0-9]", "");
if(!optout.includes.isEmpty()) ModEngineersDecor.logger.info("Pattern includes: '" + optout.includes + "'");
@ -582,6 +587,21 @@ public class ModConfig
if(!excl[i].isEmpty()) excludes_.add(excl[i]);
}
}
}
public static final void apply()
{
BlockDecorFurnace.BTileEntity.on_config(tweaks.furnace_smelting_speed_percent, tweaks.furnace_fuel_efficiency_percent, tweaks.furnace_boost_energy_consumption);
BlockDecorChair.on_config(optout.without_chair_sitting, optout.without_mob_chair_sitting, tweaks.chair_mob_sitting_probability_percent, tweaks.chair_mob_standup_probability_percent);
BlockDecorLadder.on_config(optout.without_ladder_speed_boost);
BlockDecorCraftingTable.on_config(optout.without_crafting_table_history, false, tweaks.with_crafting_quickmove_buttons);
BlockDecorPipeValve.on_config(tweaks.pipevalve_max_flowrate, tweaks.pipevalve_redstone_slope);
BlockDecorFurnaceElectrical.BTileEntity.on_config(tweaks.e_furnace_speed_percent, tweaks.e_furnace_power_consumption);
BlockDecorSolarPanel.BTileEntity.on_config(tweaks.solar_panel_peak_power);
BlockDecorBreaker.BTileEntity.on_config(tweaks.block_breaker_power_consumption, tweaks.block_breaker_reluctance, tweaks.block_breaker_min_breaking_time, tweaks.block_breaker_requires_power);
BlockDecorTreeCutter.BTileEntity.on_config(tweaks.tree_cuttter_energy_consumption, tweaks.tree_cuttter_cutting_time_needed, tweaks.tree_cuttter_requires_power);
BlockDecorMilker.BTileEntity.on_config(tweaks.milker_energy_consumption);
BlockDecorPlacer.BTileEntity.on_config();
{
// Check if the config is already synchronized or has to be synchronised.
server_config_.setBoolean("tree_cuttter_requires_power", tweaks.tree_cuttter_requires_power);