102 lines
4.3 KiB
Java
102 lines
4.3 KiB
Java
package com.dairymoose.entity.projectile;
|
|
|
|
import com.mojang.authlib.GameProfile;
|
|
import java.util.UUID;
|
|
import net.minecraft.core.particles.ItemParticleOption;
|
|
import net.minecraft.core.particles.ParticleOptions;
|
|
import net.minecraft.core.particles.ParticleTypes;
|
|
import net.minecraft.network.protocol.Packet;
|
|
import net.minecraft.resources.ResourceLocation;
|
|
import net.minecraft.server.level.ServerLevel;
|
|
import net.minecraft.server.level.ServerPlayer;
|
|
import net.minecraft.world.InteractionHand;
|
|
import net.minecraft.world.entity.Entity;
|
|
import net.minecraft.world.entity.EntityType;
|
|
import net.minecraft.world.entity.MobCategory;
|
|
import net.minecraft.world.entity.projectile.ThrowableItemProjectile;
|
|
import net.minecraft.world.item.Item;
|
|
import net.minecraft.world.item.ItemStack;
|
|
import net.minecraft.world.item.Items;
|
|
import net.minecraft.world.item.context.UseOnContext;
|
|
import net.minecraft.world.level.Level;
|
|
import net.minecraft.world.level.block.Blocks;
|
|
import net.minecraft.world.level.block.state.BlockState;
|
|
import net.minecraft.world.phys.BlockHitResult;
|
|
import net.minecraft.world.phys.EntityHitResult;
|
|
import net.minecraftforge.api.distmarker.Dist;
|
|
import net.minecraftforge.api.distmarker.OnlyIn;
|
|
import net.minecraftforge.common.util.FakePlayerFactory;
|
|
import net.minecraftforge.network.NetworkHooks;
|
|
|
|
/* loaded from: outputsrg.jar:com/dairymoose/entity/projectile/ThrownSeedEntity.class */
|
|
public class ThrownSeedEntity extends ThrowableItemProjectile {
|
|
public static final EntityType<ThrownSeedEntity> THROWN_SEED_ENTITY = EntityType.Builder.of(ThrownSeedEntity::new, MobCategory.MISC).sized(0.25f, 0.25f).clientTrackingRange(4).updateInterval(10).build(new ResourceLocation("modernlife", "thrown_seed").toString());
|
|
ServerPlayer dummy;
|
|
|
|
public ThrownSeedEntity(EntityType<? extends ThrownSeedEntity> entityType, Level world) {
|
|
super(entityType, world);
|
|
this.dummy = null;
|
|
}
|
|
|
|
public Packet<?> getAddEntityPacket() {
|
|
return NetworkHooks.getEntitySpawningPacket(this);
|
|
}
|
|
|
|
public ThrownSeedEntity(Level world, double x, double y, double z) {
|
|
super(THROWN_SEED_ENTITY, x, y, z, world);
|
|
this.dummy = null;
|
|
}
|
|
|
|
protected Item getDefaultItem() {
|
|
return Items.SNOWBALL;
|
|
}
|
|
|
|
@OnlyIn(Dist.CLIENT)
|
|
private ParticleOptions getParticle() {
|
|
ItemStack lvt_1_1_ = getItemRaw();
|
|
return lvt_1_1_.isEmpty() ? ParticleTypes.ITEM_SNOWBALL : new ItemParticleOption(ParticleTypes.ITEM, lvt_1_1_);
|
|
}
|
|
|
|
@OnlyIn(Dist.CLIENT)
|
|
public void handleEntityEvent(byte p_70103_1_) {
|
|
if (p_70103_1_ == 3) {
|
|
ParticleOptions lvt_2_1_ = getParticle();
|
|
for (int lvt_3_1_ = 0; lvt_3_1_ < 8; lvt_3_1_++) {
|
|
this.level.addParticle(lvt_2_1_, getX(), getY(), getZ(), 0.0d, 0.0d, 0.0d);
|
|
}
|
|
}
|
|
}
|
|
|
|
protected void m_8060_(BlockHitResult p_230299_1_) {
|
|
super.m_8060_(p_230299_1_);
|
|
ServerLevel serverLevel = this.level;
|
|
BlockState state = this.level.getBlockState(p_230299_1_.getBlockPos());
|
|
BlockState aboveState = this.level.getBlockState(p_230299_1_.getBlockPos().above());
|
|
if ((state.is(Blocks.FARMLAND) || (getItem() != null && getItem().getItem() == Items.NETHER_WART && state.is(Blocks.SOUL_SAND))) && aboveState.is(Blocks.AIR)) {
|
|
ItemStack itemStack = getItem();
|
|
if (itemStack != null && (serverLevel instanceof ServerLevel)) {
|
|
if (this.dummy == null) {
|
|
GameProfile profile = new GameProfile(UUID.randomUUID(), "[seed_spreader_player]");
|
|
this.dummy = FakePlayerFactory.get(serverLevel, profile);
|
|
}
|
|
this.dummy.setItemInHand(InteractionHand.MAIN_HAND, itemStack);
|
|
itemStack.useOn(new UseOnContext(this.dummy, InteractionHand.MAIN_HAND, p_230299_1_));
|
|
remove(RemovalReason.DISCARDED);
|
|
return;
|
|
}
|
|
return;
|
|
}
|
|
if (serverLevel instanceof ServerLevel) {
|
|
spawnAtLocation(getItem());
|
|
remove(RemovalReason.DISCARDED);
|
|
}
|
|
}
|
|
|
|
protected void m_5790_(EntityHitResult p_70227_1_) {
|
|
if (!this.level.isClientSide) {
|
|
spawnAtLocation(getItem());
|
|
remove(RemovalReason.DISCARDED);
|
|
}
|
|
}
|
|
}
|