Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class EntityWorldSpawnable extends LivingEntity implements IAnimatable {
- private static final EntityDataAccessor<Integer> VARIANT = SynchedEntityData.defineId(EntityWorldSpawnable.class, EntityDataSerializers.INT);
- private static final EntityDataAccessor<Float> WIDTH_SCALE = SynchedEntityData.defineId(EntityWorldSpawnable.class, EntityDataSerializers.FLOAT);
- private static final EntityDataAccessor<Float> HEIGHT_SCALE = SynchedEntityData.defineId(EntityWorldSpawnable.class, EntityDataSerializers.FLOAT);
- public static final ResourceLocation MAMMOTH_LOOT = prefix("entities/iceberg/mammoth");
- public static final ResourceLocation SMILODON_LOOT = prefix("entities/iceberg/smilodon");
- public static final ResourceLocation ERYON_LOOT = prefix("entities/iceberg/eryon");
- private AnimationFactory factory = GeckoLibUtil.createFactory(this);
- public static final Logger LOGGER = LogManager.getLogger();
- public EntityWorldSpawnable(EntityType<? extends LivingEntity> p_27557_, Level p_27558_) {
- super(p_27557_, p_27558_);
- this.refreshDimensions();
- }
- public static AttributeSupplier.Builder bakeAttributes() {
- return Mob.createMobAttributes()
- //HEALTH
- .add(Attributes.MAX_HEALTH, 10.0D)
- //SPEED
- .add(Attributes.MOVEMENT_SPEED, 0D);
- }
- @Override
- public InteractionResult interact(Player pPlayer, InteractionHand pHand) {
- ItemStack itemStack = pPlayer.getItemInHand(pHand);
- if(itemStack.isEmpty())
- {
- itemDrop();
- }
- return super.interact(pPlayer, pHand);
- }
- public void setRandomVariant()
- {
- RandomSource randomSource = this.level.random;
- float nr = randomSource.nextFloat();
- if(nr < 0.3F){
- mammothVariant();
- return;
- } else{
- smilodonVariant();
- return;
- }
- //if(nr >= 0.3 && nr < 0.5)
- //{
- //
- //}
- }
- public ResourceLocation getDeadLootTable(){
- if(getVariant() == 1){
- return SMILODON_LOOT;
- }
- if(getVariant() == 2)
- {
- return MAMMOTH_LOOT;
- }
- return ERYON_LOOT;
- }
- public void itemDrop(){
- ItemStack drop = getSoundForDrop();
- if (!drop.isEmpty() && !level.isClientSide) {
- this.spawnAtLocation(drop, 1);
- }
- }
- protected ItemStack getSoundForDrop(){
- ItemStack lootItem = getItemFromLootTable();
- if(lootItem.getItem() == UPItems.FROZEN_FOSSIL.get() || lootItem.getItem() == UPItems.SMILODON_EMBRYO.get()){
- this.playSound(SoundEvents.AMETHYST_BLOCK_CHIME, 1,1);
- } else {
- this.playSound(SoundEvents.BOOK_PAGE_TURN,1,1);
- }
- return lootItem;
- }
- public ItemStack getItemFromLootTable() {
- if(this.level.getServer() == null){
- return ItemStack.EMPTY;
- }
- LootTable loottable = this.level.getServer().getLootTables().get(this.getDeadLootTable());
- LootContext.Builder lootcontext$builder = this.createLootContext(false, DamageSource.GENERIC);
- for (ItemStack itemstack : loottable.getRandomItems(lootcontext$builder.create(LootContextParamSets.ENTITY))) {
- return itemstack;
- }
- return ItemStack.EMPTY;
- }
- private void mammothVariant(){
- setVariant(1);
- setWidthScale(5.0F);
- setHeightScale(5.0F);
- }
- private void smilodonVariant(){
- setVariant(2);
- setWidthScale(2.0F);
- setHeightScale(2.0F);
- }
- public void onSyncedDataUpdated(EntityDataAccessor<?> pKey) {
- if (HEIGHT_SCALE.equals(pKey) || WIDTH_SCALE.equals(pKey)) {
- this.refreshDimensions();
- }
- super.onSyncedDataUpdated(pKey);
- }
- @Override
- protected void defineSynchedData() {
- super.defineSynchedData();
- this.entityData.define(VARIANT, 0);
- this.entityData.define(HEIGHT_SCALE, 0F);
- this.entityData.define(WIDTH_SCALE, 0F);
- }
- @Override
- public void readAdditionalSaveData(CompoundTag compound) {
- super.readAdditionalSaveData(compound);
- this.setVariant(compound.getInt("variant"));
- this.setHeightScale(Math.min(compound.getFloat("scaleHeight"), 0F));
- this.setWidthScale(Math.min(compound.getFloat("scaleWdith"), 0F));
- }
- @Override
- public void addAdditionalSaveData(CompoundTag compound) {
- super.addAdditionalSaveData(compound);
- compound.putInt("variant", this.getVariant());
- compound.putFloat("scaleHeight", this.getHeightScale());
- compound.putFloat("scaleWdith", this.getWidthScale());
- }
- public int getVariant() {
- return this.entityData.get(VARIANT);
- }
- public void setVariant(int variant) {
- this.entityData.set(VARIANT, variant);
- }
- public float getHeightScale() {
- return this.entityData.get(HEIGHT_SCALE);
- }
- public void setHeightScale(float scale) {
- this.entityData.set(HEIGHT_SCALE, scale);
- }
- public float getWidthScale() {
- return this.entityData.get(WIDTH_SCALE);
- }
- public void setWidthScale(float scale) {
- this.entityData.set(WIDTH_SCALE, scale);
- }
- public EntityDimensions getDimensions(Pose pPose) {
- return super.getDimensions(pPose).scale(getWidthScale(), getHeightScale());
- }
- @Override
- public Iterable<ItemStack> getArmorSlots() {
- return ImmutableList.of();
- }
- @Override
- public ItemStack getItemBySlot(EquipmentSlot p_21127_) {
- return ItemStack.EMPTY;
- }
- @Override
- public void setItemSlot(EquipmentSlot p_21036_, ItemStack p_21037_) {
- }
- @Override
- protected void onInsideBlock(BlockState p_20005_) {
- }
- @Override
- public boolean canCollideWith(Entity entity) {
- return false;
- }
- @Override
- public boolean canBeCollidedWith() {
- return true;
- }
- @Override
- public boolean isPushable() {
- return false;
- }
- @Override
- public boolean hurt(DamageSource source, float damage) {
- if(source == DamageSource.IN_WALL || source == DamageSource.GENERIC)
- {
- return false;
- }
- return super.hurt(source, damage);
- }
- @Override
- public HumanoidArm getMainArm() {
- return HumanoidArm.RIGHT;
- }
- @Override
- public boolean attackable() {
- return false;
- }
- @Override
- public Packet<?> getAddEntityPacket() {
- return NetworkHooks.getEntitySpawningPacket(this);
- }
- private <E extends IAnimatable> PlayState predicate(AnimationEvent<E> event) {
- return PlayState.CONTINUE;
- }
- @Override
- public void registerControllers(AnimationData data) {
- data.addAnimationController(new AnimationController<>(this, "controller", 10, this::predicate));
- }
- @Override
- public AnimationFactory getFactory() {
- return factory;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement