-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package dev.dubhe.anvilcraft.entity; | ||
|
||
import dev.dubhe.anvilcraft.init.ModEntities; | ||
import dev.dubhe.anvilcraft.mixin.accessor.FallingBlockEntityAccessor; | ||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.world.entity.EntityType; | ||
import net.minecraft.world.entity.MoverType; | ||
import net.minecraft.world.entity.item.FallingBlockEntity; | ||
import net.minecraft.world.level.Level; | ||
import net.minecraft.world.level.block.state.BlockState; | ||
import net.minecraft.world.level.block.state.properties.BlockStateProperties; | ||
import net.minecraft.world.phys.Vec3; | ||
|
||
public class AscendingBlockEntity extends FallingBlockEntity { | ||
public AscendingBlockEntity(EntityType<? extends AscendingBlockEntity> entityType, Level level) { | ||
super(entityType, level); | ||
} | ||
|
||
private AscendingBlockEntity(Level level, double x, double y, double z, BlockState state) { | ||
this(ModEntities.ASCENDING_BLOCK_ENTITY.get(), level); | ||
((FallingBlockEntityAccessor) this).setBlockState(state); | ||
this.blocksBuilding = true; | ||
this.setPos(x, y, z); | ||
this.setDeltaMovement(Vec3.ZERO); | ||
this.xo = x; | ||
this.yo = y; | ||
this.zo = z; | ||
this.setStartPos(this.blockPosition()); | ||
} | ||
|
||
@Override | ||
public void tick() { | ||
if (this.getBlockState().isAir()) { | ||
System.out.println("this.getBlockState() = " + this.getBlockState()); | ||
this.discard(); | ||
return; | ||
} | ||
if (!this.isNoGravity()) { | ||
this.setDeltaMovement(this.getDeltaMovement().add(0.0, 0.4, 0.0)); | ||
} | ||
this.move(MoverType.SELF, this.getDeltaMovement()); | ||
if (this.level().isClientSide) return; | ||
BlockPos current = this.blockPosition(); | ||
BlockPos up = current.above(); | ||
if (!this.level().getBlockState(up).isAir()) { | ||
this.level().setBlockAndUpdate(current, this.getBlockState()); | ||
this.discard(); | ||
} | ||
this.setDeltaMovement(this.getDeltaMovement().scale(0.98)); | ||
} | ||
|
||
|
||
public static AscendingBlockEntity ascend(Level level, BlockPos pos, BlockState blockState) { | ||
Check warning on line 53 in common/src/main/java/dev/dubhe/anvilcraft/entity/AscendingBlockEntity.java
|
||
AscendingBlockEntity ascendingBlockEntity = new AscendingBlockEntity( | ||
level, | ||
pos.getX() + 0.5, | ||
pos.getY(), | ||
pos.getZ() + 0.5, | ||
blockState.hasProperty(BlockStateProperties.WATERLOGGED) | ||
? blockState.setValue(BlockStateProperties.WATERLOGGED, false) | ||
: blockState | ||
); | ||
level.setBlock(pos, blockState.getFluidState().createLegacyBlock(), 3); | ||
level.addFreshEntity(ascendingBlockEntity); | ||
return ascendingBlockEntity; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package dev.dubhe.anvilcraft.entity.render; | ||
|
||
import com.mojang.blaze3d.vertex.PoseStack; | ||
import dev.dubhe.anvilcraft.entity.AscendingBlockEntity; | ||
import net.fabricmc.api.EnvType; | ||
import net.fabricmc.api.Environment; | ||
import net.minecraft.client.renderer.ItemBlockRenderTypes; | ||
import net.minecraft.client.renderer.MultiBufferSource; | ||
import net.minecraft.client.renderer.block.BlockRenderDispatcher; | ||
import net.minecraft.client.renderer.entity.EntityRenderer; | ||
import net.minecraft.client.renderer.entity.EntityRendererProvider; | ||
import net.minecraft.client.renderer.texture.OverlayTexture; | ||
import net.minecraft.client.renderer.texture.TextureAtlas; | ||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraft.util.RandomSource; | ||
import net.minecraft.world.level.Level; | ||
import net.minecraft.world.level.block.RenderShape; | ||
import net.minecraft.world.level.block.state.BlockState; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
@Environment(EnvType.CLIENT) | ||
public class AscendingBlockRenderer extends EntityRenderer<AscendingBlockEntity> { | ||
private final BlockRenderDispatcher dispatcher; | ||
|
||
public AscendingBlockRenderer(EntityRendererProvider.Context context) { | ||
Check warning on line 26 in common/src/main/java/dev/dubhe/anvilcraft/entity/render/AscendingBlockRenderer.java
|
||
super(context); | ||
this.shadowRadius = 0.5F; | ||
this.dispatcher = context.getBlockRenderDispatcher(); | ||
} | ||
|
||
@Override | ||
public void render( | ||
AscendingBlockEntity entity, | ||
float entityYaw, | ||
float partialTicks, | ||
PoseStack poseStack, | ||
MultiBufferSource buffer, | ||
int packedLight | ||
) { | ||
BlockState blockState = entity.getBlockState(); | ||
if (blockState.getRenderShape() == RenderShape.MODEL) { | ||
Level level = entity.level(); | ||
if (blockState != level.getBlockState(entity.blockPosition()) | ||
&& blockState.getRenderShape() != RenderShape.INVISIBLE | ||
) { | ||
poseStack.pushPose(); | ||
BlockPos blockPos = BlockPos.containing(entity.getX(), entity.getBoundingBox().maxY, entity.getZ()); | ||
poseStack.translate(-0.5, 0.0, -0.5); | ||
this.dispatcher | ||
.getModelRenderer() | ||
.tesselateBlock( | ||
level, | ||
this.dispatcher.getBlockModel(blockState), | ||
blockState, | ||
blockPos, | ||
poseStack, | ||
buffer.getBuffer(ItemBlockRenderTypes.getMovingBlockRenderType(blockState)), | ||
false, | ||
RandomSource.create(), | ||
blockState.getSeed(entity.getStartPos()), | ||
OverlayTexture.NO_OVERLAY); | ||
poseStack.popPose(); | ||
super.render(entity, entityYaw, partialTicks, poseStack, buffer, packedLight); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public @NotNull ResourceLocation getTextureLocation(@NotNull AscendingBlockEntity entity) { | ||
return TextureAtlas.LOCATION_BLOCKS; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package dev.dubhe.anvilcraft.init; | ||
|
||
import com.tterrag.registrate.util.entry.EntityEntry; | ||
import dev.dubhe.anvilcraft.AnvilCraft; | ||
import dev.dubhe.anvilcraft.entity.AscendingBlockEntity; | ||
import dev.dubhe.anvilcraft.entity.render.AscendingBlockRenderer; | ||
import net.minecraft.world.entity.MobCategory; | ||
|
||
public class ModEntities { | ||
public static final EntityEntry<? extends AscendingBlockEntity> ASCENDING_BLOCK_ENTITY = AnvilCraft.REGISTRATE | ||
.entity("ascending_block", AscendingBlockEntity::new, MobCategory.MISC) | ||
.renderer(() -> AscendingBlockRenderer::new) | ||
.register(); | ||
|
||
public static void register() { | ||
// intentionally empty | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package dev.dubhe.anvilcraft.mixin.accessor; | ||
|
||
import net.minecraft.world.entity.item.FallingBlockEntity; | ||
import net.minecraft.world.level.block.state.BlockState; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.gen.Accessor; | ||
|
||
@Mixin(FallingBlockEntity.class) | ||
Check warning on line 8 in common/src/main/java/dev/dubhe/anvilcraft/mixin/accessor/FallingBlockEntityAccessor.java
|
||
public interface FallingBlockEntityAccessor { | ||
@Accessor("blockState") | ||
void setBlockState(BlockState state); | ||
} |