Skip to content

Commit 8dfb188

Browse files
committed
Amber Sinking Feature Recode
1 parent 5826753 commit 8dfb188

File tree

4 files changed

+85
-8
lines changed

4 files changed

+85
-8
lines changed

src/main/java/com/uraneptus/sullysmod/common/blocks/AmberBlock.java

+35-5
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,33 @@
11
package com.uraneptus.sullysmod.common.blocks;
22

3+
import com.uraneptus.sullysmod.core.registry.SMBlockEntityTypes;
4+
import com.uraneptus.sullysmod.core.registry.SMBlocks;
35
import net.minecraft.core.BlockPos;
6+
import net.minecraft.core.particles.ParticleTypes;
7+
import net.minecraft.util.Mth;
8+
import net.minecraft.util.RandomSource;
49
import net.minecraft.world.entity.Entity;
510
import net.minecraft.world.entity.LivingEntity;
11+
import net.minecraft.world.entity.Mob;
12+
import net.minecraft.world.entity.player.Player;
613
import net.minecraft.world.level.BlockGetter;
714
import net.minecraft.world.level.Level;
815
import net.minecraft.world.level.LightLayer;
16+
import net.minecraft.world.level.block.BaseEntityBlock;
917
import net.minecraft.world.level.block.HalfTransparentBlock;
18+
import net.minecraft.world.level.block.entity.BlockEntity;
1019
import net.minecraft.world.level.block.state.BlockState;
20+
import net.minecraft.world.phys.Vec3;
1121
import net.minecraft.world.phys.shapes.CollisionContext;
1222
import net.minecraft.world.phys.shapes.EntityCollisionContext;
1323
import net.minecraft.world.phys.shapes.Shapes;
1424
import net.minecraft.world.phys.shapes.VoxelShape;
25+
import org.jetbrains.annotations.Nullable;
1526

16-
public class AmberBlock extends HalfTransparentBlock {
27+
public class AmberBlock extends BaseEntityBlock {
1728

1829
private static final VoxelShape MELTING_COLLISION_SHAPE = Shapes.box(0.0D, 0.0D, 0.0D, 1.0D, (double)0.0F, 1.0D);
1930

20-
LivingEntity ENTITY_STUCK;
2131
public AmberBlock(Properties pProperties) {
2232
super(pProperties);
2333
}
@@ -37,8 +47,27 @@ public VoxelShape getCollisionShape(BlockState pState, BlockGetter pLevel, Block
3747
return Shapes.block();
3848
}
3949

40-
/*
50+
public void onRemove(BlockState pState, Level pLevel, BlockPos pPos, BlockState pNewState, boolean pIsMoving) {
4151

52+
//Entity entity = pLevel.getNearestEntity(new ArrayList<>(), TargetingConditions.DEFAULT, null, pPos.getX(), pPos.getY(), pPos.getZ());
53+
BlockEntity blockEntity = pLevel.getBlockEntity(pPos);
54+
assert blockEntity != null;
55+
Entity entity = pLevel.getEntity(((AmberBlockEntity) blockEntity).getStuckMob());
56+
if (entity instanceof Mob mob) {
57+
mob.setNoAi(false);
58+
}
59+
System.out.println("AMBER BROKE");
60+
super.onRemove(pState, pLevel, pPos, pNewState, pIsMoving);
61+
}
62+
63+
@Nullable
64+
@Override
65+
public BlockEntity newBlockEntity(BlockPos pPos, BlockState pState) {
66+
return SMBlockEntityTypes.AMBER.get().create(pPos, pState);
67+
}
68+
69+
70+
/*
4271
public void entityInside(BlockState pState, Level pLevel, BlockPos pPos, Entity pEntity) {
4372
if (!(pEntity instanceof LivingEntity) || pEntity.getFeetBlockState().is(this)) {
4473
if (pEntity instanceof Player) {
@@ -50,7 +79,7 @@ public void entityInside(BlockState pState, Level pLevel, BlockPos pPos, Entity
5079
mob.setRemainingFireTicks(0);
5180
mob.setInvulnerable(true);
5281
mob.setNoAi(true);
53-
ENTITY_STUCK = mob;
82+
System.out.println("MOB STUCK IN AMBER");
5483
}
5584
}
5685
if (pLevel.isClientSide) {
@@ -63,5 +92,6 @@ public void entityInside(BlockState pState, Level pLevel, BlockPos pPos, Entity
6392
}
6493
}
6594
66-
*/
95+
*/
96+
6797
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package com.uraneptus.sullysmod.common.blocks;
2+
3+
import com.uraneptus.sullysmod.core.registry.SMBlockEntityTypes;
4+
import net.minecraft.core.BlockPos;
5+
import net.minecraft.nbt.CompoundTag;
6+
import net.minecraft.world.level.block.entity.BlockEntity;
7+
import net.minecraft.world.level.block.state.BlockState;
8+
9+
public class AmberBlockEntity extends BlockEntity {
10+
11+
int stuckMobID;
12+
13+
public AmberBlockEntity(BlockPos pPos, BlockState pBlockState) {
14+
super(SMBlockEntityTypes.AMBER.get(), pPos, pBlockState);
15+
}
16+
17+
18+
public void setStuckMob(int value) {
19+
this.stuckMobID = value;
20+
}
21+
22+
public int getStuckMob() {
23+
return this.stuckMobID;
24+
}
25+
26+
27+
@Override
28+
public void load(CompoundTag compoundTag) {
29+
super.load(compoundTag);
30+
this.stuckMobID = compoundTag.getInt("StuckMobID");
31+
}
32+
@Override
33+
protected void saveAdditional(CompoundTag compoundTag) {
34+
super.saveAdditional(compoundTag);
35+
compoundTag.putInt("StuckMobID", stuckMobID);
36+
}
37+
}

src/main/java/com/uraneptus/sullysmod/core/events/SMEntityEvents.java

+9-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.uraneptus.sullysmod.core.events;
22

33
import com.uraneptus.sullysmod.SullysMod;
4+
import com.uraneptus.sullysmod.common.blocks.AmberBlockEntity;
45
import com.uraneptus.sullysmod.common.blocks.FlingerTotem;
56
import com.uraneptus.sullysmod.common.blocks.FlingerTotemBlockEntity;
67
import com.uraneptus.sullysmod.common.blocks.SMDirectionalBlock;
@@ -36,6 +37,7 @@
3637
import net.minecraft.world.entity.projectile.AbstractArrow;
3738
import net.minecraft.world.entity.projectile.Projectile;
3839
import net.minecraft.world.level.Level;
40+
import net.minecraft.world.level.block.entity.BlockEntity;
3941
import net.minecraft.world.level.block.state.BlockState;
4042
import net.minecraft.world.level.gameevent.GameEvent;
4143
import net.minecraft.world.phys.*;
@@ -199,19 +201,22 @@ public static void onLivingTick(LivingEvent.LivingTickEvent event) {
199201
Level level = entity.level();
200202
BlockState state = entity.getFeetBlockState();
201203
BlockPos blockPos = new BlockPos(entity.getBlockX(), entity.getBlockY(), entity.getBlockZ());
204+
BlockEntity blockEntity = level.getBlockEntity(blockPos);
202205

203206
if (state.is(SMBlocks.AMBER.get())) {
204207
if (entity instanceof Player) {
205208
entity.makeStuckInBlock(state, new Vec3((double) 0.8F, 0.1D, (double) 0.8F));
206209
}
207210
if (entity instanceof Mob mob) {
208211
mob.makeStuckInBlock(state, new Vec3((double) 0.0F, 0.1D, (double) 0.0F));
209-
if (mob.getSpawnType() != MobSpawnType.COMMAND) {
210-
if (mob.getBlockStateOn() != SMBlocks.AMBER.get().defaultBlockState()) {
212+
if (mob.getBlockStateOn() != SMBlocks.AMBER.get().defaultBlockState()) {
213+
if (blockEntity instanceof AmberBlockEntity amber) {
211214
mob.setSilent(true);
212215
mob.setRemainingFireTicks(0);
213216
mob.setInvulnerable(true);
214217
mob.setNoAi(true);
218+
System.out.println("MOB STUCK IN AMBER");
219+
amber.setStuckMob(mob.getId());
215220
}
216221
}
217222

@@ -223,7 +228,7 @@ public static void onLivingTick(LivingEvent.LivingTickEvent event) {
223228
level.addParticle(ParticleTypes.SOUL_FIRE_FLAME, entity.getX(), (double)(blockPos.getY() + 1), entity.getZ(), (double)(Mth.randomBetween(randomsource, -1.0F, 1.0F) * 0.083333336F), (double)0.05F, (double)(Mth.randomBetween(randomsource, -1.0F, 1.0F) * 0.083333336F));
224229
}
225230
}
226-
} else {
231+
} /* else {
227232
if (entity instanceof Mob mob) {
228233
if (mob.getSpawnType() != MobSpawnType.COMMAND && mob.isNoAi()) {
229234
mob.setSilent(false);
@@ -232,5 +237,6 @@ public static void onLivingTick(LivingEvent.LivingTickEvent event) {
232237
}
233238
}
234239
}
240+
*/
235241
}
236242
}

src/main/java/com/uraneptus/sullysmod/core/registry/SMBlockEntityTypes.java

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import com.teamabnormals.blueprint.core.util.registry.BlockEntitySubRegistryHelper;
44
import com.uraneptus.sullysmod.SullysMod;
5+
import com.uraneptus.sullysmod.common.blocks.AmberBlock;
6+
import com.uraneptus.sullysmod.common.blocks.AmberBlockEntity;
57
import com.uraneptus.sullysmod.common.blocks.FlingerTotem;
68
import com.uraneptus.sullysmod.common.blocks.FlingerTotemBlockEntity;
79
import net.minecraft.world.level.block.entity.BlockEntityType;
@@ -13,4 +15,6 @@ public class SMBlockEntityTypes {
1315
public static final BlockEntitySubRegistryHelper HELPER = SullysMod.REGISTRY_HELPER.getBlockEntitySubHelper();
1416

1517
public static final RegistryObject<BlockEntityType<FlingerTotemBlockEntity>> FLINGER_TOTEM = HELPER.createBlockEntity("flinger_totem", FlingerTotemBlockEntity::new, FlingerTotem.class);
18+
19+
public static final RegistryObject<BlockEntityType<AmberBlockEntity>> AMBER = HELPER.createBlockEntity("amber", AmberBlockEntity::new, AmberBlock.class);
1620
}

0 commit comments

Comments
 (0)