Skip to content

Commit 5826753

Browse files
committed
Amber Living Tick Event
1 parent 3799758 commit 5826753

File tree

2 files changed

+51
-48
lines changed

2 files changed

+51
-48
lines changed
Lines changed: 3 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,18 @@
11
package com.uraneptus.sullysmod.common.blocks;
22

3-
import com.uraneptus.sullysmod.core.registry.SMBlocks;
43
import net.minecraft.core.BlockPos;
5-
import net.minecraft.core.particles.ParticleTypes;
6-
import net.minecraft.server.level.ServerLevel;
7-
import net.minecraft.util.Mth;
8-
import net.minecraft.util.RandomSource;
94
import net.minecraft.world.entity.Entity;
105
import net.minecraft.world.entity.LivingEntity;
11-
import net.minecraft.world.entity.Mob;
12-
import net.minecraft.world.entity.ai.targeting.TargetingConditions;
13-
import net.minecraft.world.entity.player.Player;
146
import net.minecraft.world.level.BlockGetter;
157
import net.minecraft.world.level.Level;
168
import net.minecraft.world.level.LightLayer;
179
import net.minecraft.world.level.block.HalfTransparentBlock;
1810
import net.minecraft.world.level.block.state.BlockState;
19-
import net.minecraft.world.phys.Vec3;
2011
import net.minecraft.world.phys.shapes.CollisionContext;
2112
import net.minecraft.world.phys.shapes.EntityCollisionContext;
2213
import net.minecraft.world.phys.shapes.Shapes;
2314
import net.minecraft.world.phys.shapes.VoxelShape;
2415

25-
import java.util.ArrayList;
26-
2716
public class AmberBlock extends HalfTransparentBlock {
2817

2918
private static final VoxelShape MELTING_COLLISION_SHAPE = Shapes.box(0.0D, 0.0D, 0.0D, 1.0D, (double)0.0F, 1.0D);
@@ -48,40 +37,7 @@ public VoxelShape getCollisionShape(BlockState pState, BlockGetter pLevel, Block
4837
return Shapes.block();
4938
}
5039

51-
52-
53-
@Override
54-
public void randomTick(BlockState pState, ServerLevel pLevel, BlockPos pPos, RandomSource pRandom) {
55-
BlockPos blockPos = new BlockPos(pPos.getX(), pPos.getY() + 1, pPos.getZ());
56-
if (pLevel.getBrightness(LightLayer.BLOCK, blockPos) > 11) {
57-
System.out.println("BRIGHT");
58-
}
59-
}
60-
61-
public void onRemove(BlockState pState, Level pLevel, BlockPos pPos, BlockState pNewState, boolean pIsMoving) {
62-
63-
Entity entity = pLevel.getNearestEntity(new ArrayList<>(), TargetingConditions.DEFAULT, null, pPos.getX(), pPos.getY(), pPos.getZ());
64-
if (entity instanceof Mob mob) {
65-
mob.setNoAi(false);
66-
}
67-
if (ENTITY_STUCK instanceof Mob mob) {
68-
mob.setNoAi(false);
69-
}
70-
System.out.println("AMBER BROKE");
71-
super.onRemove(pState, pLevel, pPos, pNewState, pIsMoving);
72-
}
73-
74-
public void stepOn(Level pLevel, BlockPos pPos, BlockState pState, Entity pEntity) {
75-
BlockPos blockPos = new BlockPos(pPos.getX(), pPos.getY() + 1, pPos.getZ());
76-
if (pLevel.getBrightness(LightLayer.BLOCK, blockPos) > 11) {
77-
if (pEntity instanceof LivingEntity) {
78-
System.out.println("BRIGHT STEP");
79-
//pEntity.teleportTo(pPos.getX(), pPos.getY() - 0.5F, pPos.getZ());
80-
}
81-
}
82-
83-
super.stepOn(pLevel, pPos, pState, pEntity);
84-
}
40+
/*
8541
8642
public void entityInside(BlockState pState, Level pLevel, BlockPos pPos, Entity pEntity) {
8743
if (!(pEntity instanceof LivingEntity) || pEntity.getFeetBlockState().is(this)) {
@@ -106,4 +62,6 @@ public void entityInside(BlockState pState, Level pLevel, BlockPos pPos, Entity
10662
}
10763
}
10864
}
65+
66+
*/
10967
}

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

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,27 @@
1010
import com.uraneptus.sullysmod.core.SMConfig;
1111
import com.uraneptus.sullysmod.core.other.tags.SMBlockTags;
1212
import com.uraneptus.sullysmod.core.other.tags.SMEntityTags;
13+
import com.uraneptus.sullysmod.core.registry.SMBlocks;
1314
import com.uraneptus.sullysmod.core.registry.SMItems;
1415
import com.uraneptus.sullysmod.core.registry.SMParticleTypes;
1516
import com.uraneptus.sullysmod.core.registry.SMSounds;
1617
import net.minecraft.core.BlockPos;
1718
import net.minecraft.core.Direction;
1819
import net.minecraft.core.particles.DustColorTransitionOptions;
1920
import net.minecraft.core.particles.DustParticleOptions;
21+
import net.minecraft.core.particles.ParticleTypes;
2022
import net.minecraft.nbt.CompoundTag;
2123
import net.minecraft.server.level.ServerLevel;
2224
import net.minecraft.sounds.SoundSource;
23-
import net.minecraft.world.entity.Entity;
24-
import net.minecraft.world.entity.Mob;
25-
import net.minecraft.world.entity.TamableAnimal;
25+
import net.minecraft.util.Mth;
26+
import net.minecraft.util.RandomSource;
27+
import net.minecraft.world.entity.*;
2628
import net.minecraft.world.entity.ai.goal.target.NearestAttackableTargetGoal;
2729
import net.minecraft.world.entity.ai.goal.target.NonTameRandomTargetGoal;
2830
import net.minecraft.world.entity.animal.Ocelot;
2931
import net.minecraft.world.entity.animal.Turtle;
3032
import net.minecraft.world.entity.animal.horse.Horse;
33+
import net.minecraft.world.entity.item.ItemEntity;
3134
import net.minecraft.world.entity.monster.Zombie;
3235
import net.minecraft.world.entity.player.Player;
3336
import net.minecraft.world.entity.projectile.AbstractArrow;
@@ -188,4 +191,46 @@ public static void onEntityJoin(EntityJoinLevelEvent event) {
188191
zombie.goalSelector.addGoal(4, new GenericMobAttackTortoiseEggGoal(zombie, 1.0D, 3));
189192
}
190193
}
194+
195+
//AMBER STUFF
196+
@SubscribeEvent
197+
public static void onLivingTick(LivingEvent.LivingTickEvent event) {
198+
Entity entity = event.getEntity();
199+
Level level = entity.level();
200+
BlockState state = entity.getFeetBlockState();
201+
BlockPos blockPos = new BlockPos(entity.getBlockX(), entity.getBlockY(), entity.getBlockZ());
202+
203+
if (state.is(SMBlocks.AMBER.get())) {
204+
if (entity instanceof Player) {
205+
entity.makeStuckInBlock(state, new Vec3((double) 0.8F, 0.1D, (double) 0.8F));
206+
}
207+
if (entity instanceof Mob mob) {
208+
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()) {
211+
mob.setSilent(true);
212+
mob.setRemainingFireTicks(0);
213+
mob.setInvulnerable(true);
214+
mob.setNoAi(true);
215+
}
216+
}
217+
218+
}
219+
if (level.isClientSide) {
220+
RandomSource randomsource = level.getRandom();
221+
boolean flag = entity.xOld != entity.getX() || entity.zOld != entity.getZ();
222+
if (flag && randomsource.nextBoolean()) {
223+
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));
224+
}
225+
}
226+
} else {
227+
if (entity instanceof Mob mob) {
228+
if (mob.getSpawnType() != MobSpawnType.COMMAND && mob.isNoAi()) {
229+
mob.setSilent(false);
230+
mob.setInvulnerable(false);
231+
mob.setNoAi(false);
232+
}
233+
}
234+
}
235+
}
191236
}

0 commit comments

Comments
 (0)