Skip to content

Commit

Permalink
Finished amber sinking based on mob size
Browse files Browse the repository at this point in the history
  • Loading branch information
KekeCreations committed May 10, 2024
1 parent f7858d7 commit b8db17f
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,20 @@ public void render(AmberBE amberBlockEntity, float pPartialTick, @NotNull PoseSt

pPoseStack.pushPose();
if (level != null) {
CompoundTag compoundtag = amberBlockEntity.getEntityStuck();
if (!compoundtag.isEmpty()) {
AmberBE.removeIgnoredNBT(compoundtag);
Entity renderEntity = EntityType.loadEntityRecursive(compoundtag, level, Function.identity());

if (renderEntity instanceof LivingEntity livingEntity) {
pPoseStack.translate(0.5F, 0.0F, 0.5F);
pPoseStack.mulPose(Axis.YP.rotationDegrees(-livingEntity.getRotationVector().y));
this.renderDispatcher.setRenderShadow(false);
this.renderDispatcher.render(renderEntity, 0.0, 0.0, 0.0, 0.0F, 0, pPoseStack, pBuffer, pPackedLight);

if (amberBlockEntity.getStuckEntityData() != null) {
System.out.println(amberBlockEntity.getStuckEntityData());
CompoundTag compoundtag = amberBlockEntity.getEntityStuck();
if (!compoundtag.isEmpty()) {
AmberBE.removeIgnoredNBT(compoundtag);
Entity renderEntity = EntityType.loadEntityRecursive(compoundtag, level, Function.identity());

if (renderEntity instanceof LivingEntity livingEntity) {
pPoseStack.translate(0.5F, 0.0F, 0.5F);
pPoseStack.mulPose(Axis.YP.rotationDegrees(-livingEntity.getRotationVector().y));
this.renderDispatcher.setRenderShadow(false);
this.renderDispatcher.render(renderEntity, 0.0, 0.0, 0.0, 0.0F, 0, pPoseStack, pBuffer, pPackedLight);

}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,7 @@
import net.minecraft.network.protocol.Packet;
import net.minecraft.network.protocol.game.ClientGamePacketListener;
import net.minecraft.network.protocol.game.ClientboundBlockEntityDataPacket;
import net.minecraft.util.RandomSource;
import net.minecraft.util.random.WeightedEntry;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.Mob;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.SpawnData;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityType;
Expand All @@ -24,7 +17,6 @@
import javax.annotation.Nullable;
import java.util.Arrays;
import java.util.List;
import java.util.function.Function;

public class AmberBE extends BlockEntity {
@Nullable
Expand All @@ -45,6 +37,13 @@ public static void removeIgnoredNBT(CompoundTag pTag) {
}

}
public @Nullable StuckEntityData getStuckEntityData() {
return this.stuckEntityData;
}
public void setStuckEntityData(@Nullable StuckEntityData value) {
this.stuckEntityData = value;
this.update();
}

public boolean isBlockMelted() {
return this.isBlockMelted;
Expand Down Expand Up @@ -123,6 +122,12 @@ public CompoundTag getUpdateTag() {
return tag;
}

@Override
public void handleUpdateTag(CompoundTag tag) {
this.load(tag);
super.handleUpdateTag(tag);
}

@Override
public Packet<ClientGamePacketListener> getUpdatePacket() {
return ClientboundBlockEntityDataPacket.create(this);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.uraneptus.sullysmod.common.blocks;

import com.uraneptus.sullysmod.common.blockentities.AmberBE;
import com.uraneptus.sullysmod.common.blockentities.FlingerTotemBE;
import com.uraneptus.sullysmod.core.other.tags.SMBlockTags;
import com.uraneptus.sullysmod.core.registry.SMBlocks;
import net.minecraft.core.BlockPos;
Expand Down Expand Up @@ -29,6 +30,8 @@
import net.minecraft.world.phys.shapes.VoxelShape;
import org.jetbrains.annotations.Nullable;

import java.util.Iterator;

public class AmberBlock extends BaseEntityBlock {

private static final VoxelShape MELTING_COLLISION_SHAPE = Shapes.box(0.0D, 0.0D, 0.0D, 1.0D, 0.0F, 1.0D);
Expand Down Expand Up @@ -67,6 +70,26 @@ public VoxelShape getCollisionShape(BlockState pState, BlockGetter pLevel, Block
}
}
}
for (BlockPos pos : BlockPos.betweenClosed(pPos.offset(0, -1, 0), pPos.offset(0, -2, 0))) {
BlockState state = pLevel.getBlockState(pos);
BlockEntity be = pLevel.getBlockEntity(pos);
if (state.is(SMBlocks.AMBER.get())) {
if (be instanceof AmberBE amberBE && amberBE.hasStuckEntity()) {
CompoundTag compoundtag = amberBE.getEntityStuck();
if (level != null) {
LivingEntity livingEntity = (LivingEntity) EntityType.loadEntityRecursive(compoundtag, level, entityStuck -> entityStuck);
if (livingEntity != null) {
if (livingEntity.getBoundingBox().getYsize() > 1.5F && livingEntity.getBoundingBox().getYsize() < 2F && pos.equals(pPos.offset(0, -1, 0))) {
shouldMeltFlag = false;
}
else if (livingEntity.getBoundingBox().getYsize() >= 2F && livingEntity.getBoundingBox().getYsize() < 3.5F && pos.equals(pPos.offset(0, -2, 0))) {
shouldMeltFlag = false;
}
}
}
}
}
}
if (shouldMeltFlag) {
if (entity instanceof Player player) {
if (player.jumping) {
Expand All @@ -80,6 +103,8 @@ public VoxelShape getCollisionShape(BlockState pState, BlockGetter pLevel, Block
return MELTING_COLLISION_SHAPE;
}
}
} else {
amber.setBlockMelted(false);
}
}
}
Expand All @@ -99,6 +124,29 @@ public void onRemove(BlockState blockState, Level pLevel, BlockPos blockPos, Blo
pLevel.addFreshEntity(livingEntity);
}
}
for (BlockPos pos : BlockPos.betweenClosed(blockPos.offset(0, -1, 0), blockPos.offset(0, -2, 0))) {
BlockState state = pLevel.getBlockState(pos);
BlockEntity be = pLevel.getBlockEntity(pos);
if (state.is(SMBlocks.AMBER.get())) {
if (be instanceof AmberBE amberBE && amberBE.hasStuckEntity()) {
CompoundTag compoundtag = amberBE.getEntityStuck();
AmberBE.removeIgnoredNBT(compoundtag);
LivingEntity livingEntity = (LivingEntity) EntityType.loadEntityRecursive(compoundtag, pLevel, entityStuck -> entityStuck);
if (livingEntity != null) {
if (livingEntity.getBoundingBox().getYsize() > 1.5F && livingEntity.getBoundingBox().getYsize() < 2F && pos.equals(blockPos.offset(0, -1, 0))) {
livingEntity.moveTo(pos.getX() + 0.5, pos.getY(), pos.getZ() + 0.5);
pLevel.addFreshEntity(livingEntity);
amberBE.setStuckEntityData(null);
}
else if (livingEntity.getBoundingBox().getYsize() >= 2F && livingEntity.getBoundingBox().getYsize() < 3.5F) {
livingEntity.moveTo(pos.getX() + 0.5, pos.getY(), pos.getZ() + 0.5);
pLevel.addFreshEntity(livingEntity);
amberBE.setStuckEntityData(null);
}
}
}
}
}
}
}
super.onRemove(blockState, pLevel, blockPos, pNewState, pIsMoving);
Expand Down

0 comments on commit b8db17f

Please sign in to comment.