Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jellybean fix #1461

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.github.alexmodguy.alexscaves.server.block;

import com.github.alexmodguy.alexscaves.server.block.blockentity.GingerbarrelBlockEntity;
import com.github.alexmodguy.alexscaves.server.entity.living.GingerbreadManEntity;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.server.level.ServerLevel;
Expand All @@ -10,6 +11,7 @@
import net.minecraft.world.Containers;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.monster.piglin.PiglinAi;
import net.minecraft.world.entity.player.Player;
Expand All @@ -25,8 +27,10 @@
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.VoxelShape;
import org.spongepowered.asm.mixin.Unique;

import javax.annotation.Nullable;
import java.util.Iterator;

public class GingerbarrelBlock extends BarrelBlock {

Expand All @@ -42,16 +46,31 @@ public InteractionResult use(BlockState blockState, Level level, BlockPos blockP
if (level.isClientSide) {
return InteractionResult.SUCCESS;
} else {
BlockEntity blockentity = level.getBlockEntity(blockPos);
if (blockentity instanceof GingerbarrelBlockEntity) {
player.openMenu((GingerbarrelBlockEntity) blockentity);
BlockEntity blockEntity = level.getBlockEntity(blockPos);
if (blockEntity instanceof GingerbarrelBlockEntity gingerbarrelBlockEntity) {
if (!player.isSpectator() && !player.isCreative()) {
angerGingerbreadMen(level, player);
}
player.openMenu((GingerbarrelBlockEntity) gingerbarrelBlockEntity);
player.awardStat(Stats.OPEN_BARREL);
PiglinAi.angerNearbyPiglins(player, true);
}
return InteractionResult.CONSUME;
}
}

@Unique
private void angerGingerbreadMen(Level level, Entity opener) {
if (opener instanceof Player player) {
Iterator<GingerbreadManEntity> var4 = level.getEntitiesOfClass(GingerbreadManEntity.class, player.getBoundingBox().inflate(10, 5, 10)).iterator();
while (var4.hasNext()) {
LivingEntity entity = var4.next();
if (entity instanceof GingerbreadManEntity gingerbreadMan && !gingerbreadMan.isOvenSpawned()) {
gingerbreadMan.setTarget(player);
}
}
}
}

public void tick(BlockState state, ServerLevel level, BlockPos pos, RandomSource randomSource) {
BlockEntity blockentity = level.getBlockEntity(pos);
if (blockentity instanceof GingerbarrelBlockEntity) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ public class GummyBearEntity extends Animal implements IDancesToJukebox, IAnimat
private static final EntityDataAccessor<Float> STOMACH_BLUE = SynchedEntityData.defineId(GummyBearEntity.class, EntityDataSerializers.FLOAT);
private static final EntityDataAccessor<Integer> HELD_MOB_ID = SynchedEntityData.defineId(GummyBearEntity.class, EntityDataSerializers.INT);
private static final EntityDataAccessor<Integer> POSSESSOR_LICOWITCH_ID = SynchedEntityData.defineId(GummyBearEntity.class, EntityDataSerializers.INT);
private static final EntityDataAccessor<Integer> JELLYBEANS = SynchedEntityData.defineId(GummyBearEntity.class, EntityDataSerializers.INT);

public static final Animation ANIMATION_FISH = Animation.create(35);
public static final Animation ANIMATION_EAT = Animation.create(40);
Expand All @@ -107,8 +108,7 @@ public class GummyBearEntity extends Animal implements IDancesToJukebox, IAnimat
private int standFor = 0;
private int sitFor = 0;
private int sleepFor = 0;

private int jellybeansToMake = 5;
private int jellybeansToMake;

public GummyBearEntity(EntityType<? extends Animal> entityType, Level level) {
super(entityType, level);
Expand All @@ -125,6 +125,7 @@ protected void defineSynchedData() {
this.entityData.define(STOMACH_RED, 0.0F);
this.entityData.define(STOMACH_GREEN, 0.0F);
this.entityData.define(STOMACH_BLUE, 0.0F);
this.entityData.define(JELLYBEANS, 0);
this.entityData.define(HELD_MOB_ID, -1);
this.entityData.define(POSSESSOR_LICOWITCH_ID, -1);
}
Expand Down Expand Up @@ -186,6 +187,7 @@ public void addAdditionalSaveData(CompoundTag compound) {
compound.putBoolean("BearSitting", this.isSitting());
compound.putInt("SleepTime", sleepFor);
compound.putInt("SitTime", sitFor);
compound.putInt("Jellybeans", jellybeansToMake);
}

public void readAdditionalSaveData(CompoundTag compound) {
Expand All @@ -198,6 +200,7 @@ public void readAdditionalSaveData(CompoundTag compound) {
this.setStanding(compound.getBoolean("BearSitting"));
this.sleepFor = compound.getInt("SleepTime");
this.sitFor = compound.getInt("SitTime");
this.jellybeansToMake = compound.getInt("Jellybeans");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import net.minecraft.world.entity.projectile.Arrow;
import net.minecraft.world.entity.projectile.ProjectileUtil;
import net.minecraft.world.item.*;
import net.minecraft.world.item.enchantment.EnchantmentHelper;
import net.minecraft.world.item.enchantment.Enchantments;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.HitResult;
import net.minecraft.world.phys.Vec3;
Expand Down Expand Up @@ -210,13 +212,15 @@ public void releaseUsing(ItemStack itemStack, Level level, LivingEntity livingEn
int maxArrows = darkArrows ? 30 : 8;
abstractArrow.pickup = AbstractArrow.Pickup.ALLOWED;
for(int j = 0; j < Math.ceil(maxArrows * f); j++){
double power = 1;
if (EnchantmentHelper.getItemEnchantmentLevel(Enchantments.POWER_ARROWS, itemStack) > 0) power = EnchantmentHelper.getItemEnchantmentLevel(Enchantments.POWER_ARROWS, itemStack) * 0.5 + 0.5;
if(darkArrows){
DarkArrowEntity darkArrowEntity = new DarkArrowEntity(level, livingEntity);
darkArrowEntity.setShadowArrowDamage(precise ? 2.0F : 3.0F);
darkArrowEntity.setShadowArrowDamage(precise ? (float) (2.0F * power) : (float) (3.0F * power));
darkArrowEntity.setPerfectShot(perfectShot);
abstractArrow = darkArrowEntity;
}else if(perfectShot){
abstractArrow.setBaseDamage(abstractArrow.getBaseDamage() * 2.0F);
abstractArrow.setBaseDamage(abstractArrow.getBaseDamage() * 2.0F * power);
}
Vec3 vec3 = mutableSkyPos.getCenter().add(level.random.nextFloat() * 16 - 8, level.random.nextFloat() * 4 - 2, level.random.nextFloat() * 16 - 8);
int clearTries = 0;
Expand Down