-
Notifications
You must be signed in to change notification settings - Fork 302
Update Spectral Block/Tile #1979
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 1.20.1
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,10 @@ | |
import wayoftime.bloodmagic.common.block.type.SpectralBlockType; | ||
import wayoftime.bloodmagic.common.tile.base.TileBase; | ||
|
||
import java.util.Random; | ||
|
||
import static wayoftime.bloodmagic.common.block.BlockSpectral.SPECTRAL_STATE; | ||
|
||
public class TileSpectral extends TileBase | ||
{ | ||
public BlockState storedBlock; | ||
|
@@ -82,4 +86,23 @@ public CompoundTag serialize(CompoundTag tag) | |
tag.put("BlockState", NbtUtils.writeBlockState(storedBlock)); | ||
return tag; | ||
} | ||
|
||
public void tick() | ||
{ | ||
BlockState state = this.getBlockState(); | ||
Comment on lines
+89
to
+92
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The reason the blocks vanish so quickly is that the BE is ticked every tick. Instead, use a tick_counter and check against the DECAY_RATE and only then tick it. |
||
BlockPos pos = this.getBlockPos(); | ||
Level level = this.getLevel(); | ||
switch (state.getValue(SPECTRAL_STATE)) { | ||
case SOLID -> { | ||
level.setBlock(pos, state.setValue(SPECTRAL_STATE, SpectralBlockType.LEAKING), 3); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of '3' use the proper flag (Block.UPDATE_ALL). They are present in |
||
level.scheduleTick(pos, state.getBlock(), BlockSpectral.DECAY_RATE); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} | ||
case LEAKING -> { | ||
BlockEntity tile = level.getBlockEntity(pos); | ||
if (tile instanceof TileSpectral) { | ||
((TileSpectral) tile).revertToFluid(); | ||
} | ||
} | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you should pass the blockPos, level and tile from the lambda into the
tick
method instead of fetching them in the method. Also use the automatic cast when usinginstanceof
instead of manual casting