Updated tick

This commit is contained in:
Frank Bauer 2021-06-23 20:30:49 +02:00
parent 08fc14439a
commit 0ac3814cd5
3 changed files with 33 additions and 20 deletions

View file

@ -6,6 +6,8 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Optional; import java.util.Optional;
import net.minecraft.world.level.block.entity.BlockEntityTicker;
import net.minecraft.world.level.block.entity.BlockEntityType;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
@ -48,9 +50,11 @@ import ru.bclib.client.models.ModelsHelper;
import ru.betterend.blocks.EndBlockProperties; import ru.betterend.blocks.EndBlockProperties;
import ru.betterend.blocks.EndBlockProperties.PedestalState; import ru.betterend.blocks.EndBlockProperties.PedestalState;
import ru.betterend.blocks.InfusionPedestal; import ru.betterend.blocks.InfusionPedestal;
import ru.betterend.blocks.entities.EndStoneSmelterBlockEntity;
import ru.betterend.blocks.entities.InfusionPedestalEntity; import ru.betterend.blocks.entities.InfusionPedestalEntity;
import ru.betterend.blocks.entities.PedestalBlockEntity; import ru.betterend.blocks.entities.PedestalBlockEntity;
import ru.betterend.client.models.Patterns; import ru.betterend.client.models.Patterns;
import ru.betterend.registry.EndBlockEntities;
import ru.betterend.registry.EndBlocks; import ru.betterend.registry.EndBlocks;
import ru.betterend.rituals.InfusionRitual; import ru.betterend.rituals.InfusionRitual;
@ -429,6 +433,16 @@ public class PedestalBlock extends BaseBlockNotFull implements EntityBlock {
}; };
} }
@Nullable
public <T extends BlockEntity> BlockEntityTicker<T> getTicker(Level level, BlockEntityType<T> blockEntityType) {
return level.isClientSide() ? null : createTickerHelper(blockEntityType, EndBlockEntities.PEDESTAL, PedestalBlockEntity::tick);
}
@Nullable
protected static <E extends BlockEntity, A extends BlockEntity> BlockEntityTicker<A> createTickerHelper(BlockEntityType<A> blockEntityType, BlockEntityType<E> blockEntityType2, BlockEntityTicker<? super E> blockEntityTicker) {
return blockEntityType2 == blockEntityType ? blockEntityTicker : null;
}
static { static {
VoxelShape basinUp = Block.box(2, 3, 2, 14, 4, 14); VoxelShape basinUp = Block.box(2, 3, 2, 14, 4, 14);
VoxelShape basinDown = Block.box(0, 0, 0, 16, 3, 16); VoxelShape basinDown = Block.box(0, 0, 0, 16, 3, 16);

View file

@ -2,6 +2,7 @@ package ru.betterend.blocks.entities;
import java.util.List; import java.util.List;
import net.minecraft.core.BlockPos;
import net.minecraft.core.BlockPos.MutableBlockPos; import net.minecraft.core.BlockPos.MutableBlockPos;
import net.minecraft.core.Direction; import net.minecraft.core.Direction;
import net.minecraft.core.particles.ParticleTypes; import net.minecraft.core.particles.ParticleTypes;
@ -9,8 +10,8 @@ import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.item.ElytraItem; import net.minecraft.world.item.ElytraItem;
import net.minecraft.world.item.Item; import net.minecraft.world.item.Item;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.TickableBlockEntity;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.AABB; import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.Vec3; import net.minecraft.world.phys.Vec3;
@ -20,18 +21,16 @@ import ru.betterend.registry.EndBlockEntities;
import ru.betterend.registry.EndBlocks; import ru.betterend.registry.EndBlocks;
import ru.betterend.registry.EndParticles; import ru.betterend.registry.EndParticles;
public class BlockEntityHydrothermalVent extends BlockEntity implements TickableBlockEntity { public class BlockEntityHydrothermalVent extends BlockEntity {
private final static Vec3 POSITIVE_Y = new Vec3(0.0f, 1.0f, 0.0f); private final static Vec3 POSITIVE_Y = new Vec3(0.0f, 1.0f, 0.0f);
public BlockEntityHydrothermalVent() { public BlockEntityHydrothermalVent(BlockPos blockPos, BlockState blockState) {
super(EndBlockEntities.HYDROTHERMAL_VENT); super(EndBlockEntities.HYDROTHERMAL_VENT, blockPos, blockState);
} }
@Override public static void tick(Level level, BlockPos worldPosition, BlockState state, BlockEntityHydrothermalVent blockEntity) {
public void tick() {
if (level != null) { if (level != null) {
BlockState state = getBlockState();
if (state.is(EndBlocks.HYDROTHERMAL_VENT)) { if (state.is(EndBlocks.HYDROTHERMAL_VENT)) {
boolean active = state.getValue(HydrothermalVentBlock.ACTIVATED); boolean active = state.getValue(HydrothermalVentBlock.ACTIVATED);
if (active && level.random.nextInt(20) == 0) { if (active && level.random.nextInt(20) == 0) {
@ -56,7 +55,7 @@ public class BlockEntityHydrothermalVent extends BlockEntity implements Tickable
double mult = active ? 3.0 : 5.0; double mult = active ? 3.0 : 5.0;
float force = (float) ((1.0 - (mutable.getY() / box.maxY)) / mult); float force = (float) ((1.0 - (mutable.getY() / box.maxY)) / mult);
entities.stream().filter(entity -> (int) entity.getY() == mutable.getY() && entities.stream().filter(entity -> (int) entity.getY() == mutable.getY() &&
hasElytra(entity) && entity.isFallFlying()) blockEntity.hasElytra(entity) && entity.isFallFlying())
.forEach(entity -> entity.moveRelative(force, POSITIVE_Y)); .forEach(entity -> entity.moveRelative(force, POSITIVE_Y));
} }
mutable.move(Direction.UP); mutable.move(Direction.UP);

View file

@ -1,26 +1,27 @@
package ru.betterend.blocks.entities; package ru.betterend.blocks.entities;
import net.fabricmc.fabric.api.block.entity.BlockEntityClientSerializable; import net.fabricmc.fabric.api.block.entity.BlockEntityClientSerializable;
import net.minecraft.core.BlockPos;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.Container; import net.minecraft.world.Container;
import net.minecraft.world.entity.player.Player; import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityType; import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.entity.TickableBlockEntity;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import ru.betterend.blocks.basis.PedestalBlock; import ru.betterend.blocks.basis.PedestalBlock;
import ru.betterend.registry.EndBlockEntities; import ru.betterend.registry.EndBlockEntities;
import ru.betterend.registry.EndItems; import ru.betterend.registry.EndItems;
public class PedestalBlockEntity extends BlockEntity implements Container, TickableBlockEntity, BlockEntityClientSerializable { public class PedestalBlockEntity extends BlockEntity implements Container, BlockEntityClientSerializable {
private ItemStack activeItem = ItemStack.EMPTY; private ItemStack activeItem = ItemStack.EMPTY;
private final int maxAge = 314; private final int maxAge = 314;
private int age; private int age;
public PedestalBlockEntity() { public PedestalBlockEntity(BlockPos blockPos, BlockState blockState) {
super(EndBlockEntities.PEDESTAL); super(EndBlockEntities.PEDESTAL, blockPos, blockState);
} }
public PedestalBlockEntity(BlockEntityType<?> type) { public PedestalBlockEntity(BlockEntityType<?> type) {
@ -103,8 +104,8 @@ public class PedestalBlockEntity extends BlockEntity implements Container, Ticka
} }
@Override @Override
public void load(BlockState state, CompoundTag tag) { public void load(CompoundTag tag) {
super.load(state, tag); super.load(tag);
fromTag(tag); fromTag(tag);
} }
@ -131,12 +132,11 @@ public class PedestalBlockEntity extends BlockEntity implements Container, Ticka
} }
} }
@Override public static void tick(Level tickLevel, BlockPos tickPos, BlockState tickState, PedestalBlockEntity blockEntity) {
public void tick() { if (!blockEntity.isEmpty()) {
if (!isEmpty()) { blockEntity.age++;
age++; if (blockEntity.age > blockEntity.maxAge) {
if (age > maxAge) { blockEntity.age = 0;
age = 0;
} }
} }
} }