Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

bosko2

Members
  • Joined

  • Last visited

  1. Oh ok. Will look into it. Thank you.
  2. I would like it to spread to multiple chunks. Source will be some sort of machine that does this. Would it be better to map out NO_AIR around the source and then setting it to clear air from no air directly from Source(not from CleanAir) and doing that every 10 ticks. Also there can be a possibility that two sources are in one chunk.
  3. So I would like to have infestation(spreading) with capacity. The way it would work is by having a source block(or entity is also fine) that is going to spread blocks. Each of those blocks will implement spread more blocks. All blocks will stop spreading when capacity in source block is equal to zero. Ways I tried: Using non-Static variable in every spreading block that is linked to the Source block - ended up finding out that I can't do that Using Blockstates(Source will have capacity, and every new block will have its coordinates saved in its own blockstate, way I changed the capacity is just by replacing source blocks with a new block), problem here is that number of coordinates it to big to be handled by blockstates so java runs out of memory that way. For the first try I have no code. NO_AIR is a register for a block that this infesting block can replace. CLEAR_AIR is a register for the clear air. For the second one here it is: CleanAir block: package; //has a proper package name import net.minecraft.core.BlockPos; import net.minecraft.server.level.ServerLevel; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.StateDefinition; import net.minecraft.world.level.block.state.properties.BooleanProperty; import net.minecraft.world.level.block.state.properties.IntegerProperty; import net.minecraft.world.level.block.state.properties.Property; import org.jetbrains.annotations.NotNull; import java.util.Random; import static /*pkgname*/.BlockInit.NO_AIR; public class CleanAir extends Block { public static final Property<Integer> SOURCE_X = IntegerProperty.create("sourcex",0,29999984); public static final Property<Boolean> SOURCE_X_DIR = BooleanProperty.create("sourcexdir"); public static final Property<Integer> SOURCE_Y = IntegerProperty.create("sourcey",0,29999984); public static final Property<Boolean> SOURCE_Y_DIR = BooleanProperty.create("sourceydir"); public static final Property<Integer> SOURCE_Z = IntegerProperty.create("sourcez",0,29999984); public static final Property<Boolean> SOURCE_Z_DIR = BooleanProperty.create("sourceydir"); private static BlockPos SourcePos; public CleanAir(Properties p_49795_) { super(Properties.copy(Blocks.AIR)); } @Override public void onPlace(@NotNull BlockState blockstate, @NotNull Level world, @NotNull BlockPos pos, @NotNull BlockState oldState, boolean moving) { super.onPlace(blockstate,world,pos,oldState,moving); SourcePos = new BlockPos( blockstate.getValue(SOURCE_X)*( (blockstate.getValue(SOURCE_X_DIR))?1:-1), blockstate.getValue(SOURCE_X)*( (blockstate.getValue(SOURCE_Y_DIR))?1:-1), blockstate.getValue(SOURCE_X)*( (blockstate.getValue(SOURCE_Y_DIR))?1:-1)); world.scheduleTick(pos,this,10); } @Override public void tick(@NotNull BlockState pState, @NotNull ServerLevel pLevel, @NotNull BlockPos pPos, @NotNull Random pRandom) { super.tick(pState, pLevel, pPos, pRandom); for(int[] coord: CleanAirSource.COORDINATES) { if(pLevel.getBlockState(SourcePos).getValue(CleanAirSource.CAPACITY)==0) break; int x = coord[0]; int y = coord[1]; int z = coord[2]; BlockPos position = new BlockPos(pPos.getX() + x, pPos.getY() + y, pPos.getZ() + z); if(pLevel.getBlockState(position).is(NO_AIR.get())) { CleanAir temp = this; temp.defaultBlockState().setValue(SOURCE_X,pState.getValue(SOURCE_X)); temp.defaultBlockState().setValue(SOURCE_Y,pState.getValue(SOURCE_Y)); temp.defaultBlockState().setValue(SOURCE_Z,pState.getValue(SOURCE_Z)); temp.defaultBlockState().setValue(SOURCE_X_DIR,pState.getValue(SOURCE_X_DIR)); temp.defaultBlockState().setValue(SOURCE_Y_DIR,pState.getValue(SOURCE_Y_DIR)); temp.defaultBlockState().setValue(SOURCE_Z_DIR,pState.getValue(SOURCE_Z_DIR)); pLevel.setBlockAndUpdate(position, temp.defaultBlockState()); pLevel.setBlockAndUpdate(SourcePos,pLevel.getBlockState(SourcePos).setValue(CleanAirSource.CAPACITY,pLevel.getBlockState(SourcePos).getValue(CleanAirSource.CAPACITY)+1)); } } pLevel.scheduleTick(pPos,this,10); } @Override protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> pBuilder) { super.createBlockStateDefinition(pBuilder); pBuilder.add(SOURCE_X); pBuilder.add(SOURCE_Y); pBuilder.add(SOURCE_Z); pBuilder.add(SOURCE_X_DIR); pBuilder.add(SOURCE_Y_DIR); pBuilder.add(SOURCE_Z_DIR); } } CleanAirSource block: package; //proper package name import net.minecraft.core.BlockPos; import net.minecraft.server.level.ServerLevel; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.StateDefinition; import net.minecraft.world.level.block.state.properties.IntegerProperty; import net.minecraft.world.level.block.state.properties.Property; import org.jetbrains.annotations.NotNull; import java.util.Random; import static /*pkgname*/.BlockInit.NO_AIR; public class CleanAirSource extends Block { public static final Property<Integer> CAPACITY= IntegerProperty.create("capacity",0,256); public CleanAirSource(Properties p_49795_) { super(Properties.copy(Blocks.IRON_BLOCK)); this.registerDefaultState(this.getStateDefinition().any().setValue(CAPACITY,10)); } public static final int[][] COORDINATES={ {-1,0,0}, {0,-1,0}, {0,0,-1}, { 1,0,0}, {0, 1,0}, {0,0, 1} }; @Override public void onPlace(BlockState pState, Level pLevel, BlockPos pPos, BlockState pOldState, boolean pIsMoving) { super.onPlace(pState, pLevel, pPos, pOldState, pIsMoving); pLevel.scheduleTick(pPos,this,10); } public void tick(@NotNull BlockState pState, @NotNull ServerLevel pLevel, @NotNull BlockPos pPos, @NotNull Random pRandom) { super.tick(pState, pLevel, pPos, pRandom); for(int[] coord: COORDINATES) { int x = coord[0]; int y = coord[1]; int z = coord[2]; BlockPos position = new BlockPos(pPos.getX() + x, pPos.getY() + y, pPos.getZ() + z); if(pLevel.getBlockState(position).is(NO_AIR.get()) ) { CleanAir temp = (CleanAir) BlockInit.CLEAR_AIR.get(); pLevel.setBlockAndUpdate(position, temp.defaultBlockState() .setValue(CleanAir.SOURCE_X,java.lang.Math.abs( pPos.getX())) .setValue(CleanAir.SOURCE_Y,java.lang.Math.abs( pPos.getY())) .setValue(CleanAir.SOURCE_Z,java.lang.Math.abs( pPos.getZ())) .setValue(CleanAir.SOURCE_X_DIR,pPos.getX()>=0) .setValue(CleanAir.SOURCE_Y_DIR,pPos.getY()>=0) .setValue(CleanAir.SOURCE_Z_DIR,pPos.getZ()>=0)); } } pLevel.scheduleTick(pPos,this,10); } @Override protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> pBuilder) { super.createBlockStateDefinition(pBuilder); pBuilder.add(CAPACITY); } }

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.