Jump to content

Kenneth201998

Members
  • Posts

    77
  • Joined

  • Last visited

Converted

  • Personal Text
    I am a mod developer in the making and also seek to help those with the knowledge I discover.

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

Kenneth201998's Achievements

Stone Miner

Stone Miner (3/8)

1

Reputation

  1. Fixed it: package com.kenneth.hard_survival_craft.objects.new_ai.goal; import com.kenneth.hard_survival_craft.KenmodMain; import com.kenneth.hard_survival_craft.objects.blocks.construction.CabinDoor; import net.minecraft.block.BlockState; import net.minecraft.block.DoorBlock; import net.minecraft.block.material.Material; import net.minecraft.entity.MobEntity; import net.minecraft.entity.ai.goal.OpenDoorGoal; import net.minecraft.pathfinding.GroundPathNavigator; import net.minecraft.pathfinding.Path; import net.minecraft.pathfinding.PathPoint; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; public class CustomDoorGoal extends OpenDoorGoal { protected MobEntity entity; protected BlockPos doorPosition = BlockPos.ZERO; protected boolean doorInteract; protected boolean opened; private int closeDoorTemporisation; private final boolean closeDoor; public CustomDoorGoal(MobEntity entityIn, boolean shouldClose) { super(entityIn, shouldClose); this.entity = entityIn; this.closeDoor = shouldClose; if (!(entityIn.getNavigator() instanceof GroundPathNavigator)) { throw new IllegalArgumentException("Unsupported mob type for DoorInteractGoal"); } } @Override public boolean shouldExecute() { if(!this.entity.collidedHorizontally) { return false; } else { GroundPathNavigator groundPathNavigator = (GroundPathNavigator)this.entity.getNavigator(); Path path = groundPathNavigator.getPath(); if(path != null && !path.isFinished() && groundPathNavigator.getEnterDoors()) { for(int i = 0; i < Math.min(path.getCurrentPathIndex() + 2, path.getCurrentPathLength()); ++i) { PathPoint pathpoint = path.getPathPointFromIndex(i); this.doorPosition = new BlockPos(pathpoint.x, pathpoint.y + 1, pathpoint.z); if (!(this.entity.getDistanceSq((double)this.doorPosition.getX(), this.entity.posY, (double)this.doorPosition.getZ()) > 2.25D)) { this.doorInteract = func_220695_a(this.entity.world, this.doorPosition); if (this.doorInteract) { return true; } } } this.doorPosition = (new BlockPos(this.entity)).up(); this.doorInteract = func_220695_a(this.entity.world, this.doorPosition); return this.doorInteract; } else { return false; } } } @Override public boolean shouldContinueExecuting() { boolean test = this.closeDoor && this.closeDoorTemporisation > 0; KenmodMain.debugString("Should Continue: " + test); return test; } @Override public void startExecuting() { this.closeDoorTemporisation = 60; KenmodMain.debugString("Test 0"); this.toggleDoor(true); } @Override protected void toggleDoor(boolean open) { if (this.doorInteract) { BlockState blockstate = this.entity.world.getBlockState(this.doorPosition); if (blockstate.getBlock() instanceof DoorBlock) { ((DoorBlock)blockstate.getBlock()).toggleDoor(this.entity.world, this.doorPosition, open); } else if (blockstate.getBlock() instanceof CabinDoor){ ((CabinDoor)blockstate.getBlock()).toggleDoor(this.entity.world, this.doorPosition, open); } } } @Override public void tick() { if(this.closeDoorTemporisation > 0) { --this.closeDoorTemporisation; KenmodMain.debugString("Test 1"); } KenmodMain.debugString("Test 2"); super.tick(); } @Override public void resetTask() { this.toggleDoor(false); } public static boolean func_220695_a(World p_220695_0_, BlockPos p_220695_1_) { BlockState blockstate = p_220695_0_.getBlockState(p_220695_1_); return (blockstate.getBlock() instanceof DoorBlock || blockstate.getBlock() instanceof CabinDoor) && blockstate.getMaterial() == Material.WOOD; } } Change: @Override public boolean shouldContinueExecuting() { return this.closeDoor && this.closeDoorTemporisation > 0 && super.shouldContinueExecuting(); } To: @Override public boolean shouldContinueExecuting() { return this.closeDoor && this.closeDoorTemporisation > 0; }
  2. I know, but by using this, I found a clue as to what might be going wrong.
  3. I noticed this: @Override public void tick() { if(this.closeDoorTemporisation > 0) { --this.closeDoorTemporisation; KenmodMain.debugString("Test 1"); } super.tick(); } Kenmod.debugString("Test 1"); is only called once. And there is this: @Override public void startExecuting() { this.closeDoorTemporisation = 60; KenmodMain.debugString("Test 0"); this.toggleDoor(true); } Which is meant to set closeDoorTemporisation to 60. Does this mean that tick() is not being called properly?
  4. What I know is that resetTask() is called instantly upon opening the door.
  5. Ok so I have tried moving some things from the vanilla code and got this: package com.kenneth.hard_survival_craft.objects.new_ai.goal; import com.kenneth.hard_survival_craft.objects.blocks.construction.CabinDoor; import net.minecraft.block.BlockState; import net.minecraft.block.DoorBlock; import net.minecraft.block.material.Material; import net.minecraft.entity.MobEntity; import net.minecraft.entity.ai.goal.InteractDoorGoal; import net.minecraft.pathfinding.GroundPathNavigator; import net.minecraft.pathfinding.Path; import net.minecraft.pathfinding.PathPoint; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; public class CustomDoorGoal extends InteractDoorGoal{ protected MobEntity entity; protected BlockPos doorPosition = BlockPos.ZERO; protected boolean doorInteract; private boolean hasStoppedDoorInteraction; private float entityPositionX; private float entityPositionZ; public CustomDoorGoal(MobEntity entityIn) { super(entityIn); this.entity = entityIn; if (!(entityIn.getNavigator() instanceof GroundPathNavigator)) { throw new IllegalArgumentException("Unsupported mob type for DoorInteractGoal"); } } @Override public boolean shouldExecute() { if(!this.entity.collidedHorizontally) { return false; } else { GroundPathNavigator groundPathNavigator = (GroundPathNavigator)this.entity.getNavigator(); Path path = groundPathNavigator.getPath(); if(path != null && !path.isFinished() && groundPathNavigator.getEnterDoors()) { for(int i = 0; i < Math.min(path.getCurrentPathIndex() + 2, path.getCurrentPathLength()); ++i) { PathPoint pathpoint = path.getPathPointFromIndex(i); this.doorPosition = new BlockPos(pathpoint.x, pathpoint.y + 1, pathpoint.z); if (!(this.entity.getDistanceSq((double)this.doorPosition.getX(), this.entity.posY, (double)this.doorPosition.getZ()) > 2.25D)) { this.doorInteract = func_220695_a(this.entity.world, this.doorPosition); if (this.doorInteract) { return true; } } } this.doorPosition = (new BlockPos(this.entity)).up(); this.doorInteract = func_220695_a(this.entity.world, this.doorPosition); return this.doorInteract; } else { return false; } } } @Override public boolean shouldContinueExecuting() { return !this.hasStoppedDoorInteraction; } @Override public void startExecuting() { this.hasStoppedDoorInteraction = false; this.entityPositionX = (float)((double)((float)this.doorPosition.getX() + 0.5F) - this.entity.posX); this.entityPositionZ = (float)((double)((float)this.doorPosition.getZ() + 0.5F) - this.entity.posZ); } @Override protected void toggleDoor(boolean open) { if (this.doorInteract) { BlockState blockstate = this.entity.world.getBlockState(this.doorPosition); if (blockstate.getBlock() instanceof DoorBlock) { ((DoorBlock)blockstate.getBlock()).toggleDoor(this.entity.world, this.doorPosition, open); } else if (blockstate.getBlock() instanceof CabinDoor){ ((CabinDoor)blockstate.getBlock()).toggleDoor(this.entity.world, this.doorPosition, open); } } } @Override public void tick() { float f = (float)((double)((float)this.doorPosition.getX() + 0.5F) - this.entity.posX); float f1 = (float)((double)((float)this.doorPosition.getZ() + 0.5F) - this.entity.posZ); float f2 = this.entityPositionX * f + this.entityPositionZ * f1; if (f2 < 0.0F) { this.hasStoppedDoorInteraction = true; } } public static boolean func_220695_a(World p_220695_0_, BlockPos p_220695_1_) { BlockState blockstate = p_220695_0_.getBlockState(p_220695_1_); return (blockstate.getBlock() instanceof DoorBlock || blockstate.getBlock() instanceof CabinDoor) && blockstate.getMaterial() == Material.WOOD; } } They still don't open the door. EDIT: package com.kenneth.hard_survival_craft.objects.new_ai.goal; import com.kenneth.hard_survival_craft.objects.blocks.construction.CabinDoor; import net.minecraft.block.BlockState; import net.minecraft.block.DoorBlock; import net.minecraft.block.material.Material; import net.minecraft.entity.MobEntity; import net.minecraft.entity.ai.goal.OpenDoorGoal; import net.minecraft.pathfinding.GroundPathNavigator; import net.minecraft.pathfinding.Path; import net.minecraft.pathfinding.PathPoint; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; public class CustomDoorGoal extends OpenDoorGoal { protected MobEntity entity; protected BlockPos doorPosition = BlockPos.ZERO; protected boolean doorInteract; private int closeDoorTemporisation; private final boolean closeDoor; public CustomDoorGoal(MobEntity entityIn, boolean shouldClose) { super(entityIn, shouldClose); this.entity = entityIn; this.closeDoor = shouldClose; if (!(entityIn.getNavigator() instanceof GroundPathNavigator)) { throw new IllegalArgumentException("Unsupported mob type for DoorInteractGoal"); } } @Override public boolean shouldExecute() { if(!this.entity.collidedHorizontally) { return false; } else { GroundPathNavigator groundPathNavigator = (GroundPathNavigator)this.entity.getNavigator(); Path path = groundPathNavigator.getPath(); if(path != null && !path.isFinished() && groundPathNavigator.getEnterDoors()) { for(int i = 0; i < Math.min(path.getCurrentPathIndex() + 2, path.getCurrentPathLength()); ++i) { PathPoint pathpoint = path.getPathPointFromIndex(i); this.doorPosition = new BlockPos(pathpoint.x, pathpoint.y + 1, pathpoint.z); if (!(this.entity.getDistanceSq((double)this.doorPosition.getX(), this.entity.posY, (double)this.doorPosition.getZ()) > 2.25D)) { this.doorInteract = func_220695_a(this.entity.world, this.doorPosition); if (this.doorInteract) { return true; } } } this.doorPosition = (new BlockPos(this.entity)).up(); this.doorInteract = func_220695_a(this.entity.world, this.doorPosition); return this.doorInteract; } else { return false; } } } @Override public boolean shouldContinueExecuting() { return this.closeDoor && this.closeDoorTemporisation > 0 && super.shouldContinueExecuting(); } @Override public void startExecuting() { this.closeDoorTemporisation = 60; this.toggleDoor(true); } @Override protected void toggleDoor(boolean open) { if (this.doorInteract) { BlockState blockstate = this.entity.world.getBlockState(this.doorPosition); if (blockstate.getBlock() instanceof DoorBlock) { ((DoorBlock)blockstate.getBlock()).toggleDoor(this.entity.world, this.doorPosition, open); } else if (blockstate.getBlock() instanceof CabinDoor){ ((CabinDoor)blockstate.getBlock()).toggleDoor(this.entity.world, this.doorPosition, open); } } } @Override public void resetTask() { this.toggleDoor(false); } @Override public void tick() { --this.closeDoorTemporisation; super.tick(); } public static boolean func_220695_a(World p_220695_0_, BlockPos p_220695_1_) { BlockState blockstate = p_220695_0_.getBlockState(p_220695_1_); return (blockstate.getBlock() instanceof DoorBlock || blockstate.getBlock() instanceof CabinDoor) && blockstate.getMaterial() == Material.WOOD; } } They can now open doors but the door closes almost instantly upon opening. Its like the door opens then 1 tick later it closes. How to fix?
  6. Ok so I have tried: package com.kenneth.hard_survival_craft.objects.new_ai.join_handlers; import com.kenneth.hard_survival_craft.KenmodMain; import com.kenneth.hard_survival_craft.objects.new_ai.goal.CustomDoorGoal; import net.minecraft.entity.merchant.villager.AbstractVillagerEntity; import net.minecraftforge.event.entity.EntityJoinWorldEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; public class CustomVillagerJoinHandler { @SubscribeEvent public void onJoinWorld(EntityJoinWorldEvent evt) { if(evt.getEntity() instanceof AbstractVillagerEntity) { AbstractVillagerEntity ent = (AbstractVillagerEntity)evt.getEntity(); CustomDoorGoal test = new CustomDoorGoal(ent); ent.goalSelector.addGoal(1, test); KenmodMain.debugString("TEST 001"); } } } And: package com.kenneth.hard_survival_craft.objects.new_ai.goal; import com.kenneth.hard_survival_craft.objects.blocks.construction.CabinDoor; import net.minecraft.block.BlockState; import net.minecraft.block.DoorBlock; import net.minecraft.entity.MobEntity; import net.minecraft.entity.ai.goal.InteractDoorGoal; import net.minecraft.pathfinding.GroundPathNavigator; import net.minecraft.util.math.BlockPos; public class CustomDoorGoal extends InteractDoorGoal{ protected MobEntity entity; protected BlockPos doorPosition = BlockPos.ZERO; protected boolean doorInteract; public CustomDoorGoal(MobEntity entityIn) { super(entityIn); this.entity = entityIn; if (!(entityIn.getNavigator() instanceof GroundPathNavigator)) { throw new IllegalArgumentException("Unsupported mob type for DoorInteractGoal"); } } @Override protected void toggleDoor(boolean open) { if (this.doorInteract) { BlockState blockstate = this.entity.world.getBlockState(this.doorPosition); if (blockstate.getBlock() instanceof DoorBlock) { ((DoorBlock)blockstate.getBlock()).toggleDoor(this.entity.world, this.doorPosition, open); } else if (blockstate.getBlock() instanceof CabinDoor){ ((CabinDoor)blockstate.getBlock()).toggleDoor(this.entity.world, this.doorPosition, open); } } } } And: private void clientRegistries (final FMLClientSetupEvent event) { MinecraftForge.EVENT_BUS.register(new CustomVillagerJoinHandler()); debugString("Client registries method registered..."); } But still they don't open the doors.
  7. What if I were to copy the villager code and add a goal to it? Where would the code be that I can do this? Edit: How can I add a goal to an existing entity?
  8. Any way I can add to vanilla villagers to make them open my doors? How could I code my own entities to open the door?
  9. Here is the code for my door: package com.kenneth.hard_survival_craft.objects.blocks.construction; import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; import net.minecraft.block.DoorBlock; import net.minecraft.block.HorizontalBlock; import net.minecraft.block.material.Material; import net.minecraft.block.material.PushReaction; import net.minecraft.entity.LivingEntity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.BlockItemUseContext; import net.minecraft.item.ItemStack; import net.minecraft.pathfinding.PathType; import net.minecraft.state.BooleanProperty; import net.minecraft.state.DirectionProperty; import net.minecraft.state.EnumProperty; import net.minecraft.state.StateContainer.Builder; import net.minecraft.state.properties.BlockStateProperties; import net.minecraft.state.properties.DoorHingeSide; import net.minecraft.state.properties.DoubleBlockHalf; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.Direction; import net.minecraft.util.Hand; import net.minecraft.util.Mirror; import net.minecraft.util.Rotation; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockRayTraceResult; import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.Vec3d; import net.minecraft.util.math.shapes.ISelectionContext; import net.minecraft.util.math.shapes.VoxelShape; import net.minecraft.world.IBlockReader; import net.minecraft.world.IWorld; import net.minecraft.world.IWorldReader; import net.minecraft.world.World; public class CabinDoor extends DoorBlock { public static final DirectionProperty FACING = HorizontalBlock.HORIZONTAL_FACING; public static final BooleanProperty OPEN = BlockStateProperties.OPEN; public static final EnumProperty<DoorHingeSide> HINGE = BlockStateProperties.DOOR_HINGE; public static final BooleanProperty POWERED = BlockStateProperties.POWERED; public static final EnumProperty<DoubleBlockHalf> HALF = BlockStateProperties.DOUBLE_BLOCK_HALF; protected static final VoxelShape default_shape = Block.makeCuboidShape(0, 0, 7, 16, 16, 9); protected static final VoxelShape north_south = Block.makeCuboidShape(0, 0, 7, 16, 16, 9); protected static final VoxelShape east_west = Block.makeCuboidShape(7, 0, 0, 9, 16, 16); protected static final VoxelShape south_l = Block.makeCuboidShape(13, 0, 7, 16, 16, 21); protected static final VoxelShape south_r = Block.makeCuboidShape(0, 0, 7, 3, 16, 21); protected static final VoxelShape north_l = Block.makeCuboidShape(0, 0, 9, 3, 16, -5); protected static final VoxelShape north_r = Block.makeCuboidShape(13, 0, 9, 16, 16, -5); protected static final VoxelShape east_l = Block.makeCuboidShape(7, 0, 0, 21, 16, 3); protected static final VoxelShape east_r = Block.makeCuboidShape(7, 0, 13, 21, 16, 16); protected static final VoxelShape west_l = Block.makeCuboidShape(9, 0, 13, -5, 16, 16); protected static final VoxelShape west_r = Block.makeCuboidShape(9, 0, 0, -5, 16, 3); public CabinDoor(Properties properties) { super(properties); this.setDefaultState(this.stateContainer.getBaseState().with(OPEN, Boolean.valueOf(false))); } @Override public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) { Direction dir = state.get(FACING); DoorHingeSide side = state.get(HINGE); Boolean open = state.get(OPEN); if((dir == Direction.NORTH || dir == Direction.SOUTH) && open == false) { return north_south; } else if ((dir == Direction.EAST || dir == Direction.WEST) && open == false) { return east_west; } else if(dir == Direction.NORTH && side == DoorHingeSide.LEFT) { return north_l; } else if (dir == Direction.NORTH && side == DoorHingeSide.RIGHT) { return north_r; } else if(dir == Direction.SOUTH && side == DoorHingeSide.LEFT) { return south_l; } else if (dir == Direction.SOUTH && side == DoorHingeSide.RIGHT) { return south_r; } else if (dir == Direction.EAST && side == DoorHingeSide.LEFT) { return east_l; } else if (dir == Direction.EAST && side == DoorHingeSide.RIGHT) { return east_r; } else if (dir == Direction.WEST && side == DoorHingeSide.LEFT) { return west_l; } else if (dir == Direction.WEST && side == DoorHingeSide.RIGHT) { return west_r; } else { return default_shape; } } @Override public BlockState updatePostPlacement(BlockState stateIn, Direction facing, BlockState facingState, IWorld worldIn, BlockPos currentPos, BlockPos facingPos) { DoubleBlockHalf doubleblockhalf = stateIn.get(HALF); if (facing.getAxis() == Direction.Axis.Y && doubleblockhalf == DoubleBlockHalf.LOWER == (facing == Direction.UP)) { return facingState.getBlock() == this && facingState.get(HALF) != doubleblockhalf ? stateIn.with(FACING, facingState.get(FACING)).with(OPEN, facingState.get(OPEN)).with(HINGE, facingState.get(HINGE)).with(POWERED, facingState.get(POWERED)) : Blocks.AIR.getDefaultState(); } else { return doubleblockhalf == DoubleBlockHalf.LOWER && facing == Direction.DOWN && !stateIn.isValidPosition(worldIn, currentPos) ? Blocks.AIR.getDefaultState() : super.updatePostPlacement(stateIn, facing, facingState, worldIn, currentPos, facingPos); } } @Override public void harvestBlock(World worldIn, PlayerEntity player, BlockPos pos, BlockState state, TileEntity te, ItemStack stack) { super.harvestBlock(worldIn, player, pos, Blocks.AIR.getDefaultState(), te, stack); } @Override public void onBlockHarvested(World worldIn, BlockPos pos, BlockState state, PlayerEntity player) { DoubleBlockHalf doubleblockhalf = state.get(HALF); BlockPos blockpos = doubleblockhalf == DoubleBlockHalf.LOWER ? pos.up() : pos.down(); BlockState blockstate = worldIn.getBlockState(blockpos); if (blockstate.getBlock() == this && blockstate.get(HALF) != doubleblockhalf) { worldIn.setBlockState(blockpos, Blocks.AIR.getDefaultState(), 35); worldIn.playEvent(player, 2001, blockpos, Block.getStateId(blockstate)); ItemStack itemstack = player.getHeldItemMainhand(); if (!worldIn.isRemote && !player.isCreative()) { Block.spawnDrops(state, worldIn, pos, (TileEntity)null, player, itemstack); Block.spawnDrops(blockstate, worldIn, blockpos, (TileEntity)null, player, itemstack); } } super.onBlockHarvested(worldIn, pos, state, player); } @Override public boolean allowsMovement(BlockState state, IBlockReader worldIn, BlockPos pos, PathType type) { switch(type) { case LAND: return state.get(OPEN); case WATER: return false; case AIR: return state.get(OPEN); default: return false; } } private int getCloseSound() { return this.material == Material.IRON ? 1011 : 1012; } private int getOpenSound() { return this.material == Material.IRON ? 1005 : 1006; } @Override public BlockState getStateForPlacement(BlockItemUseContext context) { BlockPos blockpos = context.getPos(); if (blockpos.getY() < 255 && context.getWorld().getBlockState(blockpos.up()).isReplaceable(context)) { World world = context.getWorld(); boolean flag = world.isBlockPowered(blockpos) || world.isBlockPowered(blockpos.up()); return this.getDefaultState().with(FACING, context.getPlacementHorizontalFacing()).with(HINGE, this.getHingeSide(context)).with(POWERED, Boolean.valueOf(flag)).with(OPEN, Boolean.valueOf(flag)).with(HALF, DoubleBlockHalf.LOWER); } else { return null; } } @Override public void onBlockPlacedBy(World worldIn, BlockPos pos, BlockState state, LivingEntity placer, ItemStack stack) { worldIn.setBlockState(pos.up(), state.with(HALF, DoubleBlockHalf.UPPER), 3); } private DoorHingeSide getHingeSide(BlockItemUseContext p_208073_1_) { IBlockReader iblockreader = p_208073_1_.getWorld(); BlockPos blockpos = p_208073_1_.getPos(); Direction direction = p_208073_1_.getPlacementHorizontalFacing(); BlockPos blockpos1 = blockpos.up(); Direction direction1 = direction.rotateYCCW(); BlockPos blockpos2 = blockpos.offset(direction1); BlockState blockstate = iblockreader.getBlockState(blockpos2); BlockPos blockpos3 = blockpos1.offset(direction1); BlockState blockstate1 = iblockreader.getBlockState(blockpos3); Direction direction2 = direction.rotateY(); BlockPos blockpos4 = blockpos.offset(direction2); BlockState blockstate2 = iblockreader.getBlockState(blockpos4); BlockPos blockpos5 = blockpos1.offset(direction2); BlockState blockstate3 = iblockreader.getBlockState(blockpos5); int i = (blockstate.func_224756_o(iblockreader, blockpos2) ? -1 : 0) + (blockstate1.func_224756_o(iblockreader, blockpos3) ? -1 : 0) + (blockstate2.func_224756_o(iblockreader, blockpos4) ? 1 : 0) + (blockstate3.func_224756_o(iblockreader, blockpos5) ? 1 : 0); boolean flag = blockstate.getBlock() == this && blockstate.get(HALF) == DoubleBlockHalf.LOWER; boolean flag1 = blockstate2.getBlock() == this && blockstate2.get(HALF) == DoubleBlockHalf.LOWER; if ((!flag || flag1) && i <= 0) { if ((!flag1 || flag) && i >= 0) { int j = direction.getXOffset(); int k = direction.getZOffset(); Vec3d vec3d = p_208073_1_.getHitVec(); double d0 = vec3d.x - (double)blockpos.getX(); double d1 = vec3d.z - (double)blockpos.getZ(); return (j >= 0 || !(d1 < 0.5D)) && (j <= 0 || !(d1 > 0.5D)) && (k >= 0 || !(d0 > 0.5D)) && (k <= 0 || !(d0 < 0.5D)) ? DoorHingeSide.LEFT : DoorHingeSide.RIGHT; } else { return DoorHingeSide.LEFT; } } else { return DoorHingeSide.RIGHT; } } @Override public boolean onBlockActivated(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand handIn, BlockRayTraceResult hit) { if (this.material == Material.IRON) { return false; } else { state = state.cycle(OPEN); worldIn.setBlockState(pos, state, 10); worldIn.playEvent(player, state.get(OPEN) ? this.getOpenSound() : this.getCloseSound(), pos, 0); return true; } } @Override public void toggleDoor(World worldIn, BlockPos pos, boolean open) { BlockState blockstate = worldIn.getBlockState(pos); if (blockstate.getBlock() == this && blockstate.get(OPEN) != open) { worldIn.setBlockState(pos, blockstate.with(OPEN, Boolean.valueOf(open)), 10); this.playSound(worldIn, pos, open); } } @Override public void neighborChanged(BlockState state, World worldIn, BlockPos pos, Block blockIn, BlockPos fromPos, boolean isMoving) { boolean flag = worldIn.isBlockPowered(pos) || worldIn.isBlockPowered(pos.offset(state.get(HALF) == DoubleBlockHalf.LOWER ? Direction.UP : Direction.DOWN)); if (blockIn != this && flag != state.get(POWERED)) { if (flag != state.get(OPEN)) { this.playSound(worldIn, pos, flag); } worldIn.setBlockState(pos, state.with(POWERED, Boolean.valueOf(flag)).with(OPEN, Boolean.valueOf(flag)), 2); } } @Override public boolean isValidPosition(BlockState state, IWorldReader worldIn, BlockPos pos) { BlockPos blockpos = pos.down(); BlockState blockstate = worldIn.getBlockState(blockpos); if (state.get(HALF) == DoubleBlockHalf.LOWER) { return blockstate.func_224755_d(worldIn, blockpos, Direction.UP); } else { return blockstate.getBlock() == this; } } private void playSound(World worldIn, BlockPos pos, boolean open) { worldIn.playEvent((PlayerEntity)null, open ? this.getOpenSound() : this.getCloseSound(), pos, 0); } @Override public PushReaction getPushReaction(BlockState state) { return PushReaction.DESTROY; } @Override public BlockState rotate(BlockState state, Rotation rot) { return state.with(FACING, rot.rotate(state.get(FACING))); } @Override public BlockState mirror(BlockState state, Mirror mirrorIn) { return mirrorIn == Mirror.NONE ? state : state.rotate(mirrorIn.toRotation(state.get(FACING))).cycle(HINGE); } @Override public long getPositionRandom(BlockState state, BlockPos pos) { return MathHelper.getCoordinateRandom(pos.getX(), pos.down(state.get(HALF) == DoubleBlockHalf.LOWER ? 0 : 1).getY(), pos.getZ()); } @Override public boolean isSolid(BlockState state) { return false; } @Override protected void fillStateContainer(Builder<Block, BlockState> builder) { builder.add(HALF, FACING, OPEN, HINGE, POWERED); } } They still don't interact with it. Remember the door goes through the middle of the block instead of at the edge. Refer to my mod's images to see what the door looks like: https://www.curseforge.com/minecraft/mc-mods/kenneths-log-cabin-blocks EDIT: The villagers crowd around the door but can't open it
  10. How do I add a new door that villagers / zombies can use? Also: - Vanilla doors are always placed on the edge of blocks. - My modded doors are placed through the middle of blocks. If this will affect their AI in any way I need to know. Thanks.
  11. Ok I have ran into one more problem: package com.kenneth.hard_survival_craft.objects.blocks.workstations.smelting_forge; import com.kenneth.hard_survival_craft.objects.blocks.BlockList; import com.kenneth.hard_survival_craft.objects.custom_capabilities.block_capabilites.CapabilityProgress; import com.kenneth.hard_survival_craft.objects.custom_capabilities.block_capabilites.CapabilityProgressGoal; import com.kenneth.hard_survival_craft.objects.custom_capabilities.block_capabilites.CapabilityBurnTime; import com.kenneth.hard_survival_craft.objects.custom_capabilities.block_capabilites.IProgress; import com.kenneth.hard_survival_craft.objects.custom_capabilities.block_capabilites.IProgressGoal; import com.kenneth.hard_survival_craft.objects.custom_capabilities.block_capabilites.IBurnTime; import com.kenneth.hard_survival_craft.objects.custom_capabilities.block_capabilites.Progress; import com.kenneth.hard_survival_craft.objects.custom_capabilities.block_capabilites.ProgressGoal; import com.kenneth.hard_survival_craft.objects.custom_capabilities.block_capabilites.BurnTime; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerInventory; import net.minecraft.entity.player.ServerPlayerEntity; import net.minecraft.inventory.InventoryHelper; import net.minecraft.inventory.container.Container; import net.minecraft.inventory.container.INamedContainerProvider; import net.minecraft.item.ItemStack; import net.minecraft.item.Items; import net.minecraft.nbt.CompoundNBT; import net.minecraft.network.NetworkManager; import net.minecraft.network.play.server.SUpdateTileEntityPacket; import net.minecraft.tileentity.ITickableTileEntity; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.Direction; import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.StringTextComponent; import net.minecraftforge.common.capabilities.Capability; import net.minecraftforge.common.util.INBTSerializable; import net.minecraftforge.common.util.LazyOptional; import net.minecraftforge.fml.network.NetworkHooks; import net.minecraftforge.items.CapabilityItemHandler; import net.minecraftforge.items.IItemHandler; import net.minecraftforge.items.ItemStackHandler; public class SmeltingForgeTileEntity extends TileEntity implements ITickableTileEntity, INamedContainerProvider { protected ItemStackHandler slots = new ItemStackHandler(); private LazyOptional<IItemHandler> slots_holder = LazyOptional.of(() -> slots); private LazyOptional<IProgress> progress = LazyOptional.of(this::createProgress); private LazyOptional<IProgressGoal> progress_goal = LazyOptional.of(this::createGoal); private LazyOptional<IBurnTime> burn_time = LazyOptional.of(this::createBurnTime); public SmeltingForgeTileEntity() { super(BlockList.smelting_forge_tile_entity); slots = new ItemStackHandler(); slots.setSize(4); } @Override public void tick() { if(getProgressGoal() != 300) { setGoal(300); } if(itemsValid() && (getBurnTime() > 0 || hasFuel())) { incrementProgress(1); if(getProgress() >= getProgressGoal()) { smelt(); setProgress(0); } } else if (getProgress() > 0){ decrementProgress(1); } //Decrement burn time: if(getBurnTime() > 0) { decrementBurn(1); } else if (hasFuel() && itemsValid()) { //If burn time reaches zero and there is still fuel and there is items left to smelt then reset the burn time: setBurn(400); slots.getStackInSlot(2).shrink(1); } if(isBurning() && world.getBlockState(pos).get(SmeltingForge.LIT) == false) { world.setBlockState(pos, world.getBlockState(pos).with(SmeltingForge.LIT, true).with(SmeltingForge.FACING, world.getBlockState(pos).get(SmeltingForge.FACING))); } else if (!isBurning() && world.getBlockState(pos).get(SmeltingForge.LIT) == true){ world.setBlockState(pos, world.getBlockState(pos).with(SmeltingForge.LIT, false).with(SmeltingForge.FACING, world.getBlockState(pos).get(SmeltingForge.FACING))); } markDirty(); } public boolean isBurning () { return getBurnTime() > 0 || (hasFuel() && itemsValid()); } //Check if there is fuel left in slot 2: private boolean hasFuel () { if(slots.getStackInSlot(2).getItem() == Items.COAL || slots.getStackInSlot(2).getItem() == Items.CHARCOAL) { return true; } return false; } //Check if the inventory has proper items for smelting: private boolean itemsValid () { if(slots.getStackInSlot(0).getItem() == Items.IRON_INGOT && ((slots.getStackInSlot(3).getItem() == Items.GOLD_INGOT && slots.getStackInSlot(3).getCount() < slots.getStackInSlot(3).getMaxStackSize()) || slots.getStackInSlot(3) == ItemStack.EMPTY) && (slots.getStackInSlot(1).getItem() == Items.COAL || slots.getStackInSlot(1).getItem() == Items.CHARCOAL)) { return true; } return false; } //Smelt something: private void smelt () { if(slots.getStackInSlot(3) == ItemStack.EMPTY) { slots.setStackInSlot(3, new ItemStack(Items.GOLD_INGOT, 1)); } else { slots.getStackInSlot(3).setCount(slots.getStackInSlot(3).getCount() + 1); } slots.getStackInSlot(0).shrink(1); slots.getStackInSlot(1).shrink(1); } public int getProgress() { int prog = this.getCapability(CapabilityProgress.PROGRESS).map(IProgress::getProgress).orElse(0); return prog; } public int getProgressGoal () { int goal = this.getCapability(CapabilityProgressGoal.PROGRESS_GOAL).map(IProgressGoal::getGoal).orElse(0) + 1; return goal; } public int getBurnTime () { int burn = this.getCapability(CapabilityBurnTime.BURN_TIME).map(IBurnTime::getBurnTime).orElse(0); return burn; } private void incrementProgress (int amount) { progress.ifPresent(p -> ((Progress)p).incrementProgress(amount)); } private void decrementProgress (int amount) { progress.ifPresent(p -> ((Progress)p).decrementProgress(amount)); } private void setProgress (int amount) { progress.ifPresent(p -> ((Progress)p).setProgress(amount)); } private void setGoal (int amount) { progress_goal.ifPresent(g -> ((ProgressGoal)g).setGoal(amount)); } private void decrementBurn (int amount) { burn_time.ifPresent(b -> ((BurnTime)b).decrementBurnTime(amount)); } private void setBurn (int amount) { burn_time.ifPresent(b -> ((BurnTime)b).setBurnTime(amount)); } private IProgress createProgress () { return new Progress(0); } private IProgressGoal createGoal () { return new ProgressGoal(0); } private IBurnTime createBurnTime () { return new BurnTime(0); } @Override public SUpdateTileEntityPacket getUpdatePacket() { return new SUpdateTileEntityPacket(this.pos, 0, this.getUpdateTag()); } @Override public CompoundNBT getUpdateTag() { return this.write(new CompoundNBT()); } @Override public void onDataPacket(NetworkManager net, SUpdateTileEntityPacket pkt) { read(pkt.getNbtCompound()); } @SuppressWarnings("unchecked") @Override public void read(CompoundNBT tag) { slots.deserializeNBT(tag.getCompound("slots")); CompoundNBT progressTag = tag.getCompound("progress"); CompoundNBT progessGoalTag = tag.getCompound("progress_goal"); CompoundNBT burnTimeTag = tag.getCompound("burn_time"); progress.ifPresent(h -> ((INBTSerializable<CompoundNBT>)h).deserializeNBT(progressTag)); progress_goal.ifPresent(i -> ((INBTSerializable<CompoundNBT>)i).deserializeNBT(progessGoalTag)); burn_time.ifPresent(j -> ((INBTSerializable<CompoundNBT>)j).deserializeNBT(burnTimeTag)); super.read(tag); } @SuppressWarnings("unchecked") @Override public CompoundNBT write(CompoundNBT tag) { tag.put("slots", slots.serializeNBT()); progress.ifPresent(h -> { CompoundNBT compound = ((INBTSerializable<CompoundNBT>)h).serializeNBT(); tag.put("progress", compound); }); progress_goal.ifPresent(i -> { CompoundNBT compound = ((INBTSerializable<CompoundNBT>)i).serializeNBT(); tag.put("progress_goal", compound); }); burn_time.ifPresent(j -> { CompoundNBT compound = ((INBTSerializable<CompoundNBT>)j).serializeNBT(); tag.put("burn_time", compound); }); return super.write(tag); } @Override public <T> LazyOptional<T> getCapability(Capability<T> cap, Direction side) { if(cap == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) { return slots_holder.cast(); } if(cap == CapabilityProgress.PROGRESS) { return progress.cast(); } if(cap == CapabilityProgressGoal.PROGRESS_GOAL) { return progress_goal.cast(); } if(cap == CapabilityBurnTime.BURN_TIME) { return burn_time.cast(); } return super.getCapability(cap, side); } @Override public Container createMenu(int id, PlayerInventory player_inventory, PlayerEntity player) { return new SmeltingForgeContainer(id, player_inventory, slots, this); } @Override public ITextComponent getDisplayName() { return new StringTextComponent("block.kenmodlcb.furnace_station"); } public void openGUI (ServerPlayerEntity player) { if(!world.isRemote) { NetworkHooks.openGui(player, this, getPos()); } } @Override public void remove() { super.remove(); slots_holder.invalidate(); progress.invalidate(); progress_goal.invalidate(); burn_time.invalidate(); } public void onDestroyed () { for(int i = 0; i < 4; i++) { if(slots.getStackInSlot(i) != ItemStack.EMPTY) { InventoryHelper.spawnItemStack(world, pos.getX(), pos.getY(), pos.getZ(), slots.getStackInSlot(i)); } } } } package com.kenneth.hard_survival_craft.objects.blocks.workstations.smelting_forge; //import com.kenneth.hard_survival_craft.KenmodMain; import com.kenneth.hard_survival_craft.objects.blocks.BlockList; import com.kenneth.hard_survival_craft.objects.custom_capabilities.block_capabilites.BurnTime; import com.kenneth.hard_survival_craft.objects.custom_capabilities.block_capabilites.CapabilityBurnTime; import com.kenneth.hard_survival_craft.objects.custom_capabilities.block_capabilites.CapabilityProgress; import com.kenneth.hard_survival_craft.objects.custom_capabilities.block_capabilites.CapabilityProgressGoal; import com.kenneth.hard_survival_craft.objects.custom_capabilities.block_capabilites.IProgress; import com.kenneth.hard_survival_craft.objects.custom_capabilities.block_capabilites.Progress; import com.kenneth.hard_survival_craft.objects.custom_capabilities.block_capabilites.ProgressGoal; import net.minecraft.client.Minecraft; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerInventory; import net.minecraft.inventory.container.Container; import net.minecraft.inventory.container.Slot; import net.minecraft.item.ItemStack; import net.minecraft.network.PacketBuffer; import net.minecraft.util.IntReferenceHolder; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.items.IItemHandler; import net.minecraftforge.items.ItemStackHandler; import net.minecraftforge.items.SlotItemHandler; public class SmeltingForgeContainer extends Container { SmeltingForgeTileEntity tile_entity; @OnlyIn(Dist.CLIENT) public SmeltingForgeContainer (int id, PlayerInventory player_inventory, PacketBuffer extra_data) { this(id, player_inventory, new ItemStackHandler(4), (SmeltingForgeTileEntity)Minecraft.getInstance().world.getTileEntity(extra_data.readBlockPos())); } public SmeltingForgeContainer(int id, PlayerInventory player_inventory, IItemHandler smelting_forge_inventory, SmeltingForgeTileEntity te) { super(BlockList.smelting_forge_container, id); this.addSlot(new SlotItemHandler(smelting_forge_inventory, 0, 17, 21)); this.addSlot(new SlotItemHandler(smelting_forge_inventory, 1, 44, 21)); this.addSlot(new SlotItemHandler(smelting_forge_inventory, 2, 17, 57)); this.addSlot(new SlotItemHandler(smelting_forge_inventory, 3, 98, 39) { @Override public boolean isItemValid(ItemStack stack) { return false; } }); int si; int sj; for (si = 0; si < 3; ++si) { for (sj = 0; sj < 9; ++sj) { this.addSlot(new Slot(player_inventory, sj + (si + 1) * 9, 0 + 8 + sj * 18, 0 + 84 + si * 18)); } } for (si = 0; si < 9; ++si) { this.addSlot(new Slot(player_inventory, si, 0 + 8 + si * 18, 0 + 142)); } this.tile_entity = te; trackInt(new IntReferenceHolder() { @Override public void set(int value) { tile_entity.getCapability(CapabilityProgress.PROGRESS).ifPresent(h -> ((Progress)h).setProgress(value)); } @Override public int get() { return getProgress(); } }); trackInt(new IntReferenceHolder() { @Override public void set(int value) { tile_entity.getCapability(CapabilityProgressGoal.PROGRESS_GOAL).ifPresent(h -> ((ProgressGoal)h).setGoal(value)); } @Override public int get() { return getGoal(); } }); trackInt(new IntReferenceHolder() { @Override public void set(int value) { tile_entity.getCapability(CapabilityBurnTime.BURN_TIME).ifPresent(j -> ((BurnTime)j).setBurnTime(value)); } @Override public int get() { return getBurnTime(); } }); } @Override public ItemStack transferStackInSlot(PlayerEntity playerIn, int index) { ItemStack itemstack = ItemStack.EMPTY; Slot slot = (Slot) this.inventorySlots.get(index); if (slot != null && slot.getHasStack()) { ItemStack itemstack1 = slot.getStack(); itemstack = itemstack1.copy(); if (index < 4) { if (!this.mergeItemStack(itemstack1, 4, this.inventorySlots.size(), true)) { return ItemStack.EMPTY; } slot.onSlotChange(itemstack1, itemstack); } else if (!this.mergeItemStack(itemstack1, 0, 4, false)) { if (index < 4 + 27) { if (!this.mergeItemStack(itemstack1, 4 + 27, this.inventorySlots.size(), true)) { return ItemStack.EMPTY; } } else { if (!this.mergeItemStack(itemstack1, 4, 4 + 27, false)) { return ItemStack.EMPTY; } } return ItemStack.EMPTY; } if (itemstack1.getCount() == 0) { slot.putStack(ItemStack.EMPTY); } else { slot.onSlotChanged(); } if (itemstack1.getCount() == itemstack.getCount()) { return ItemStack.EMPTY; } slot.onTake(playerIn, itemstack1); } return itemstack; } @Override protected boolean mergeItemStack(ItemStack stack, int startIndex, int endIndex, boolean reverseDirection) { boolean flag = false; int i = startIndex; if (reverseDirection) { i = endIndex - 1; } if (stack.isStackable()) { while (!stack.isEmpty()) { if (reverseDirection) { if (i < startIndex) { break; } } else if (i >= endIndex) { break; } Slot slot = this.inventorySlots.get(i); ItemStack itemstack = slot.getStack(); if (slot.isItemValid(itemstack) && !itemstack.isEmpty() && areItemsAndTagsEqual(stack, itemstack)) { int j = itemstack.getCount() + stack.getCount(); int maxSize = Math.min(slot.getSlotStackLimit(), stack.getMaxStackSize()); if (j <= maxSize) { stack.setCount(0); itemstack.setCount(j); slot.putStack(itemstack); flag = true; } else if (itemstack.getCount() < maxSize) { stack.shrink(maxSize - itemstack.getCount()); itemstack.setCount(maxSize); slot.putStack(itemstack); flag = true; } } if (reverseDirection) { --i; } else { ++i; } } } if (!stack.isEmpty()) { if (reverseDirection) { i = endIndex - 1; } else { i = startIndex; } while (true) { if (reverseDirection) { if (i < startIndex) { break; } } else if (i >= endIndex) { break; } Slot slot1 = this.inventorySlots.get(i); ItemStack itemstack1 = slot1.getStack(); if (itemstack1.isEmpty() && slot1.isItemValid(stack)) { if (stack.getCount() > slot1.getSlotStackLimit()) { slot1.putStack(stack.split(slot1.getSlotStackLimit())); } else { slot1.putStack(stack.split(stack.getCount())); } slot1.onSlotChanged(); flag = true; break; } if (reverseDirection) { --i; } else { ++i; } } } return flag; } public int getProgress () { //KenmodMain.debugString("test 0: " + tile_entity.getProgress()); return tile_entity.getCapability(CapabilityProgress.PROGRESS).map(IProgress::getProgress).orElse(0); } public int getGoal () { //KenmodMain.debugString("test 1: " + tile_entity.getProgressGoal()); return tile_entity.getProgressGoal(); } public int getBurnTime () { //KenmodMain.debugString("test 2: " + tile_entity.getBurnTime()); return tile_entity.getBurnTime(); } @Override public void onContainerClosed(PlayerEntity playerIn) { super.onContainerClosed(playerIn); } @Override public boolean canInteractWith(PlayerEntity playerIn) { return true; } } package com.kenneth.hard_survival_craft.objects.blocks.workstations.smelting_forge; import org.lwjgl.opengl.GL11; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.screen.inventory.ContainerScreen; import net.minecraft.entity.player.PlayerInventory; import net.minecraft.util.ResourceLocation; import net.minecraft.util.text.ITextComponent; public class SmeltingForgeGUI extends ContainerScreen<SmeltingForgeContainer> { private static final ResourceLocation texture = new ResourceLocation("kenmod:textures/gui/smelting_forge_gui.png"); public SmeltingForgeGUI(SmeltingForgeContainer screenContainer, PlayerInventory inv, ITextComponent titleIn) { super(screenContainer, inv, titleIn); this.xSize = 176; this.ySize = 166; } @Override public void render(int mouseX, int mouseY, float partialTicks) { this.renderBackground(); super.render(mouseX, mouseY, partialTicks); this.renderHoveredToolTip(mouseX, mouseY); } @Override protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) { GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); Minecraft.getInstance().getTextureManager().bindTexture(texture); int k = (this.width - this.xSize) / 2; int l = (this.height - this.ySize) / 2; this.blit(k, l, 0, 0, this.xSize, this.ySize); int cook_progress = Math.round(24 * getCookProgressScaled()); int le = this.guiLeft; int to = this.guiTop; this.blit(le + 67, to + 39, 176, 14, cook_progress + 1, 16); int burn_time = Math.round(13 - (13.0F * getBurnTimeScaled())); this.blit(le + 17, to + 39 + 13 - burn_time, 176, 12 - burn_time, 14, burn_time); } private float getBurnTimeScaled() { int burn = container.getBurnTime(); int burn_goal = 400; if(burn_goal == 0) { return 0; } else { return 1.0F - ((float)burn / (float)burn_goal); } } private float getCookProgressScaled () { int prog = container.getProgress(); int goal = container.getGoal(); return (float)prog / (float) goal; } @Override protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) { this.font.drawString("Smelting Forge", 16, 5, -1); } @Override public void tick() { super.tick(); } @Override public void removed() { super.removed(); Minecraft.getInstance().keyboardListener.enableRepeatEvents(false); } @Override public void init(Minecraft minecraft, int width, int height) { super.init(minecraft, width, height); minecraft.keyboardListener.enableRepeatEvents(true); } } When looking at the progress arrow it will go forwards for a little bit, then jerk back a little, then continue going forward. What is causing this strangeness?
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.