forked from SlimeKnights/TinkersConstruct
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGlowballEntity.java
More file actions
87 lines (73 loc) · 2.84 KB
/
GlowballEntity.java
File metadata and controls
87 lines (73 loc) · 2.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package slimeknights.tconstruct.gadgets.entity;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.protocol.Packet;
import net.minecraft.network.protocol.game.ClientGamePacketListener;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.projectile.ThrowableItemProjectile;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.EntityHitResult;
import net.minecraft.world.phys.HitResult;
import net.minecraftforge.entity.IEntityAdditionalSpawnData;
import net.minecraftforge.network.NetworkHooks;
import slimeknights.tconstruct.gadgets.TinkerGadgets;
import slimeknights.tconstruct.shared.TinkerCommons;
import javax.annotation.Nonnull;
/** @deprecated use {@link slimeknights.tconstruct.tools.entity.ThrownShuriken} */
@Deprecated
public class GlowballEntity extends ThrowableItemProjectile implements IEntityAdditionalSpawnData {
public GlowballEntity(EntityType<? extends GlowballEntity> p_i50159_1_, Level p_i50159_2_) {
super(p_i50159_1_, p_i50159_2_);
}
public GlowballEntity(Level worldIn, LivingEntity throwerIn) {
super(TinkerGadgets.glowBallEntity.get(), throwerIn, worldIn);
}
public GlowballEntity(Level worldIn, double x, double y, double z) {
super(TinkerGadgets.glowBallEntity.get(), x, y, z, worldIn);
}
@Override
protected Item getDefaultItem() {
return TinkerGadgets.glowBall.get();
}
@SuppressWarnings("ConstantConditions") // getType() enforces the class type
@Override
protected void onHit(HitResult result) {
Level level = level();
if (!level.isClientSide) {
BlockPos position = null;
Direction direction = Direction.DOWN;
if (result.getType() == HitResult.Type.ENTITY) {
position = ((EntityHitResult) result).getEntity().blockPosition();
}
if (result.getType() == HitResult.Type.BLOCK) {
BlockHitResult blockHit = (BlockHitResult) result;
position = blockHit.getBlockPos().relative(blockHit.getDirection());
direction = blockHit.getDirection().getOpposite();
}
if (position != null) {
TinkerCommons.glowBlock.get().addGlow(level, position, direction);
}
}
if (!level.isClientSide) {
level.broadcastEntityEvent(this, (byte) 3);
this.discard();
}
}
@Override
public void writeSpawnData(FriendlyByteBuf buffer) {
buffer.writeItem(this.getItemRaw());
}
@Override
public void readSpawnData(FriendlyByteBuf additionalData) {
this.setItem(additionalData.readItem());
}
@Nonnull
@Override
public Packet<ClientGamePacketListener> getAddEntityPacket() {
return NetworkHooks.getEntitySpawningPacket(this);
}
}