matt1999rd
Members-
Posts
133 -
Joined
-
Last visited
Everything posted by matt1999rd
-
[1.14-newer] how to keep value when closing minecraft
matt1999rd replied to matt1999rd's topic in Modder Support
my code is not good I will come later because I saw errror in logger that prevent the tileentity to reload -
[1.14-newer] deprecated method onBlockActivated
matt1999rd replied to matt1999rd's topic in Modder Support
ok I have done it and it works thank you for information -
[1.14-newer] deprecated method onBlockActivated
matt1999rd replied to matt1999rd's topic in Modder Support
the method onBlockActivated is also deprecated... -
[1.14-newer] deprecated method onBlockActivated
matt1999rd replied to matt1999rd's topic in Modder Support
okay so we can override a method of BlockState class within a class extended from Block...is that right ? because it seems to me very strange... -
[1.14-newer] how to keep value when closing minecraft
matt1999rd replied to matt1999rd's topic in Modder Support
I create my own capability class is this a good idea ? because it compiled but doesn't work... I copy the code from EnergyCapability... -
hello, In my mod I want to keep the value of a variable when closing minecraft and I don't know how to do it . It is three integer from a BlockPos...
-
[1.14-newer] deprecated method onBlockActivated
matt1999rd replied to matt1999rd's topic in Modder Support
okay so how can I replace it if I cannot use blockState ? I saw on other post that people in 1.14 are using onBlockActivated too and nothing is suggest to replace it in the Block class unfortunately... -
[1.14-newer] deprecated method onBlockActivated
matt1999rd replied to matt1999rd's topic in Modder Support
thanks but the problem is that I need to create a new BlockState class for my block so that I can redefine it and I thinks it is not a good idea and not as simple as you may think. -
[1.14-newer] deprecated method onBlockActivated
matt1999rd replied to matt1999rd's topic in Modder Support
I have checked within blockstate class and I didn't find any function that indicate whether this block is clicked or not... So I don't know where I could find a way not to use this. Maybe if some of you have example of such usage, I will be happy. -
[1.14-newer] deprecated method onBlockActivated
matt1999rd replied to matt1999rd's topic in Modder Support
what do you mean by blockstate ? -
Hello everyone, In the 1.14 tutorial of McJty, when creating a gui, he used the @Deprecated function onBlockActivated to open the gui when the block is clicked by the player. I want to do it with newer method that are not deprecated to follow the rules suggested in the common issue and recommendation. Does such a function exist or we ought to use the deprecated one ?
-
yes it change the facing properties from east west or south to north (because as I think it is the first one)
-
here is all the code of the new block : public class SwitchDoubleTurn extends Switch { private static EnumProperty<Corners> SWITCH_POSITION; static { SWITCH_POSITION = EnumProperty.create("switch_position",Corners.class,(corners -> { return (corners == Corners.TURN_LEFT|| corners == Corners.TURN_RIGHT ); })); } private BlockState blockState; public SwitchDoubleTurn() { super(true,Properties.create(Material.IRON) .doesNotBlockMovement() .lightValue(0) .hardnessAndResistance(2f) .sound(SoundType.METAL)); setRegistryName("double_turn_switch"); this.setDefaultState(this.stateContainer.getBaseState() .with(BlockStateProperties.HORIZONTAL_FACING,Direction.NORTH) .with(SWITCH_POSITION,Corners.TURN_LEFT) .with(RAIL_STRAIGHT_FLAT,RailShape.NORTH_SOUTH) ); blockState=this.getDefaultState(); } @Override public boolean isIn(Tag<Block> tag) { return (tag == BlockTags.RAILS); } @Override public boolean canMakeSlopes(BlockState p_canMakeSlopes_1_, IBlockReader p_canMakeSlopes_2_, BlockPos p_canMakeSlopes_3_) { return false; } @Override public boolean isValidPosition(BlockState p_196260_1_, IWorldReader p_196260_2_, BlockPos p_196260_3_) { return true; } private Corners actualState ; public SwitchDoubleTurn(Properties builder) { super(true,builder); setRegistryName("double_turn_switch"); } @Override public void onBlockPlacedBy(World world, BlockPos pos, BlockState state, @Nullable LivingEntity entity, ItemStack stack) { if (entity !=null) { world.setBlockState(pos,state .with(BlockStateProperties.HORIZONTAL_FACING,getFacingFromEntity(entity, pos)) .with(SWITCH_POSITION,Corners.TURN_LEFT) .with(RAIL_STRAIGHT_FLAT,RailShape.NORTH_SOUTH) ); actualState = Corners.TURN_LEFT; blockState=state; } } private Direction getFacingFromEntity(LivingEntity entity, BlockPos pos) { Direction d= Direction.getFacingFromVector( (float) (entity.posX-pos.getX()), (float) (entity.posY-pos.getY()), (float) (entity.posZ-pos.getZ())); return d; } @Override public void fillStateContainer(StateContainer.Builder<Block,BlockState> builder){ builder.add(BlockStateProperties.HORIZONTAL_FACING, SWITCH_POSITION, RAIL_STRAIGHT_FLAT); } @Override public BlockState getBlockState() { return blockState; } public void updatePoweredState(World world, BlockState state, BlockPos pos, int flags) { if (!world.isRemote){ boolean isPowered = (actualState == Corners.TURN_RIGHT); System.out.println("valeur de state.get(...): "+state.get(SWITCH_POSITION)); if (!isPowered){ System.out.println("changing to turn_right position"); world.setBlockState(pos,state.with(SWITCH_POSITION,Corners.TURN_RIGHT),flags); actualState = Corners.TURN_RIGHT; }else { System.out.println("changing to turn_left position"); world.setBlockState(pos,state.with(SWITCH_POSITION,Corners.TURN_LEFT),flags); actualState = Corners.TURN_LEFT; } } } @Override public RailShape getRailDirection(BlockState state, IBlockReader reader, BlockPos pos, @Nullable AbstractMinecartEntity minecartEntity) { Direction direction = state.get(BlockStateProperties.HORIZONTAL_FACING); switch (direction) { case NORTH: return (actualState == Corners.TURN_LEFT)? RailShape.SOUTH_WEST : RailShape.SOUTH_EAST; case SOUTH: return (actualState == Corners.TURN_LEFT)? RailShape.NORTH_EAST : RailShape.NORTH_WEST; case WEST: return (actualState == Corners.TURN_LEFT)? RailShape.SOUTH_EAST : RailShape.NORTH_EAST; case EAST: return (actualState == Corners.TURN_LEFT)? RailShape.NORTH_WEST : RailShape.SOUTH_WEST; default: throw new IllegalArgumentException("no such direction for double turn block"); } } @Override public IProperty<RailShape> getShapeProperty() { return RAIL_STRAIGHT_FLAT; } } RAIL_STRAIGHT_FLAT est une enumproperty qui contient les railshape north_south et east_west mais elle n'est pas utile et je ne sais pas comment ne plus avoir de railshape property pour mon block
-
mcjty has done some tutorial on making if you got an idea of changing this to make a new gui for 1.14 that fit what you wanted, I would be interested in. What he does is not really what you want nor it is not what I wanted because it involves inventory. Here is the video :
-
creating item that change the state of a block
matt1999rd replied to matt1999rd's topic in Modder Support
my block is actally in this tags as I've overriden the function isIn. I think that may be the point. I've not tried though -
in the new onItemUse function it returns ActionResultType When I just put the return statement like that : @Override public ActionResultType onItemUse(ItemUseContext context) { return ActionResultType.SUCCESS; } I get for one of my newest block a change in the blockstate which is reinitialised
-
so I'm wandering if it is normal that this function reset the blockstate of blocks. For example if I create a block with facing properties when I clicked on the block with the new item, is it normal that the new facing properties become DOWN as its meta value is the smaller one ?
-
Hello !! I'm working on a mod that use item and I have got one question : how does onItemUse work in new version ? what does this do on blocks ?
-
creating item that change the state of a block
matt1999rd replied to matt1999rd's topic in Modder Support
Rail are changing depending on the other rail but I don't know if I can modify the function that change the position regarding neighbor rail.. -
creating item that change the state of a block
matt1999rd replied to matt1999rd's topic in Modder Support
now the problem is solved but in fact one problem remain is that the main block I use for creating the block is herited from AbstractRailBlock so when I put the block within the game the switch change the shape when I call this function -
creating item that change the state of a block
matt1999rd replied to matt1999rd's topic in Modder Support
the state is not changing and it is not working -
creating item that change the state of a block
matt1999rd replied to matt1999rd's topic in Modder Support
the ispowered is always at true statement -
creating item that change the state of a block
matt1999rd replied to matt1999rd's topic in Modder Support
so have you got an idea of what is not working ? I'm pretty sure it's the function setBlockState but I do not understood what flags changes.. -
creating item that change the state of a block
matt1999rd replied to matt1999rd's topic in Modder Support
I've understand here is the code : public void updatePoweredState(World world, BlockState state, BlockPos pos, int flags) { if (!world.isRemote){ boolean isPowered = (state.get(SWITCH_POSITION) == Corners.TURN); if (!isPowered){ world.setBlockState(pos,state.with(SWITCH_POSITION,Corners.TURN),flags); }else { world.setBlockState(pos,state.with(SWITCH_POSITION,Corners.STRAIGHT),flags); } System.out.println(state.get(SWITCH_POSITION)); } } I don't need string but this enumproperty will be usefull in my future block I filtered the position from now -
creating item that change the state of a block
matt1999rd replied to matt1999rd's topic in Modder Support
I use string to compare rather than using boolean because it seems not to work with booleanProperty POWERED (that the property I used before)