|
| 1 | +package plus.dragons.createenchantmentindustry.mixin; |
| 2 | + |
| 3 | +import com.simibubi.create.AllItems; |
| 4 | +import com.simibubi.create.content.kinetics.crusher.CrushingWheelControllerBlock; |
| 5 | +import com.simibubi.create.content.kinetics.crusher.CrushingWheelControllerBlockEntity; |
| 6 | +import net.createmod.catnip.math.VecHelper; |
| 7 | +import net.minecraft.core.Direction; |
| 8 | +import net.minecraft.nbt.NbtUtils; |
| 9 | +import net.minecraft.server.level.ServerLevel; |
| 10 | +import net.minecraft.world.entity.Entity; |
| 11 | +import net.minecraft.world.entity.LivingEntity; |
| 12 | +import net.minecraft.world.entity.item.ItemEntity; |
| 13 | +import net.minecraft.world.item.ItemStack; |
| 14 | +import net.minecraft.world.phys.Vec3; |
| 15 | +import org.spongepowered.asm.mixin.Mixin; |
| 16 | +import org.spongepowered.asm.mixin.Shadow; |
| 17 | +import org.spongepowered.asm.mixin.injection.At; |
| 18 | +import org.spongepowered.asm.mixin.injection.Inject; |
| 19 | +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; |
| 20 | +import plus.dragons.createenchantmentindustry.config.CEIConfig; |
| 21 | + |
| 22 | +@Mixin(CrushingWheelControllerBlockEntity.class) |
| 23 | +public class CrushingWheelControllerBlockEntityMixin { |
| 24 | + |
| 25 | + @Shadow(remap = false) |
| 26 | + public Entity processingEntity; |
| 27 | + |
| 28 | + @Inject(method = "tick", |
| 29 | + at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/Entity;setPos(DDD)V", shift = At.Shift.AFTER)) |
| 30 | + private void injected(CallbackInfo ci) { |
| 31 | + if(CEIConfig.kinetics().crushingWheelKillDropXp.get() && !processingEntity.isAlive() && processingEntity instanceof LivingEntity livingEntity){ |
| 32 | + if(!(processingEntity.level() instanceof ServerLevel serverLevel)) return; |
| 33 | + int reward = Math.max((int) Math.floor(livingEntity.getExperienceReward(serverLevel,processingEntity) * CEIConfig.kinetics().crushingWheelKillDropXpScale.get()),1); |
| 34 | + if(reward >= 1000 || Math.random( ) < CEIConfig.kinetics().crushingWheelKillDropXpRate.get()){ |
| 35 | + int count = reward/3 + ((Math.random()<(reward%3/3f))? 1: 0); |
| 36 | + if(count!=0){ |
| 37 | + var self = (CrushingWheelControllerBlockEntity)(Object)this; |
| 38 | + Vec3 centerPos = VecHelper.getCenterOf(self.getBlockPos()); |
| 39 | + Direction facing = self.getBlockState().getValue(CrushingWheelControllerBlock.FACING); |
| 40 | + int offset = facing.getAxisDirection() |
| 41 | + .getStep(); |
| 42 | + Vec3 outSpeed = new Vec3((facing.getAxis() == Direction.Axis.X ? 0.25D : 0.0D) * offset, |
| 43 | + offset == 1 ? (facing.getAxis() == Direction.Axis.Y ? 0.5D : 0.0D) : 0.0D, |
| 44 | + (facing.getAxis() == Direction.Axis.Z ? 0.25D : 0.0D) * offset); |
| 45 | + Vec3 outPos = centerPos.add((facing.getAxis() == Direction.Axis.X ? .55f * offset : 0f), |
| 46 | + (facing.getAxis() == Direction.Axis.Y ? .55f * offset : 0f), (facing.getAxis() == Direction.Axis.Z ? .55f * offset : 0f)); |
| 47 | + var expItem = new ItemEntity(processingEntity.level(),outPos.x(),outPos.y(),outPos.z(), new ItemStack(AllItems.EXP_NUGGET.get(),count)); |
| 48 | + expItem.setDeltaMovement(outSpeed); |
| 49 | + expItem.getPersistentData() |
| 50 | + .put("BypassCrushingWheel", NbtUtils.writeBlockPos(self.getBlockPos())); |
| 51 | + processingEntity.level().addFreshEntity(expItem); |
| 52 | + } |
| 53 | + } |
| 54 | + } |
| 55 | + |
| 56 | + } |
| 57 | +} |
0 commit comments