Add server-only crossbow ammunition and copper rail speed controls
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
package online.astradev.content.mixin;
|
||||
|
||||
import java.util.function.Predicate;
|
||||
import net.minecraft.world.item.*;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.entity.projectile.Projectile;
|
||||
import online.astradev.content.weapon.Ammunition;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.*;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
@Mixin(CrossbowItem.class)
|
||||
public abstract class CrossbowMixin {
|
||||
@Inject(method = {"getSupportedHeldProjectiles()Ljava/util/function/Predicate;", "getAllSupportedProjectiles()Ljava/util/function/Predicate;"}, at = @At("RETURN"), cancellable = true)
|
||||
private void astra$ammo(CallbackInfoReturnable<Predicate<ItemStack>> cir) { cir.setReturnValue(cir.getReturnValue().or(Ammunition::accepts)); }
|
||||
@Inject(method = "createProjectile", at = @At("HEAD"), cancellable = true)
|
||||
private void astra$create(Level level, LivingEntity owner, ItemStack weapon, ItemStack ammo, boolean critical, CallbackInfoReturnable<Projectile> cir) {
|
||||
if (Ammunition.accepts(ammo)) cir.setReturnValue(Ammunition.create(level, owner, ammo));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package online.astradev.content.mixin;
|
||||
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.world.entity.vehicle.minecart.*;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import online.astradev.content.rail.CartSpeed;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.*;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
@Mixin(NewMinecartBehavior.class)
|
||||
public abstract class ExperimentalCartMixin extends MinecartBehavior {
|
||||
protected ExperimentalCartMixin(AbstractMinecart cart){super(cart);}
|
||||
@Inject(method="calculateTrackSpeed",at=@At("RETURN"),cancellable=true)
|
||||
private void astra$exactSpeed(CallbackInfoReturnable<Vec3> cir) {
|
||||
if(!(level() instanceof ServerLevel level))return;
|
||||
double limit=((CartSpeed)minecart).astracontent$limit(level);
|
||||
var movement=cir.getReturnValue();
|
||||
if(limit>0 && movement.horizontalDistance()>limit)cir.setReturnValue(movement.scale(limit/movement.horizontalDistance()));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package online.astradev.content.mixin;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.world.entity.vehicle.minecart.MinecartFurnace;
|
||||
import online.astradev.content.rail.CartSpeed;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.*;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
@Mixin(MinecartFurnace.class)
|
||||
public abstract class FurnaceCartMixin {
|
||||
@Inject(method="getMaxSpeed",at=@At("RETURN"),cancellable=true)
|
||||
private void astra$furnace(ServerLevel level,CallbackInfoReturnable<Double> cir) {
|
||||
double limit=((CartSpeed)this).astracontent$limit(level);if(limit>0)cir.setReturnValue(limit);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package online.astradev.content.mixin;
|
||||
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.world.entity.vehicle.minecart.AbstractMinecart;
|
||||
import net.minecraft.world.level.storage.*;
|
||||
import online.astradev.content.rail.RailSpeed;
|
||||
import org.spongepowered.asm.mixin.*;
|
||||
import org.spongepowered.asm.mixin.injection.*;
|
||||
import org.spongepowered.asm.mixin.injection.callback.*;
|
||||
|
||||
@Mixin(AbstractMinecart.class)
|
||||
public abstract class MinecartMixin implements online.astradev.content.rail.CartSpeed {
|
||||
@Unique private double astra$speed;
|
||||
@Inject(method="getMaxSpeed",at=@At("RETURN"),cancellable=true)
|
||||
private void astra$limit(ServerLevel level,CallbackInfoReturnable<Double> cir) {
|
||||
double limit=astracontent$limit(level);
|
||||
if(limit>0)cir.setReturnValue(limit);
|
||||
}
|
||||
@Override public double astracontent$limit(ServerLevel level) {
|
||||
var cart=(AbstractMinecart)(Object)this;
|
||||
astra$speed=RailSpeed.target(level,cart.getCurrentBlockPosOrRailBelow(),astra$speed);
|
||||
// Preserve existing experimental gamerules until this cart reaches a regulator.
|
||||
if(astra$speed==0) return 0;
|
||||
double limit=RailSpeed.safeLimit(cart,level,astra$speed/20);
|
||||
return limit*(cart.isInWater()?.5:1);
|
||||
}
|
||||
@Inject(method="addAdditionalSaveData",at=@At("RETURN"))
|
||||
private void astra$save(ValueOutput out,CallbackInfo ci) { if(astra$speed>0)out.putDouble("AstraContentSpeed",astra$speed); }
|
||||
@Inject(method="readAdditionalSaveData",at=@At("RETURN"))
|
||||
private void astra$read(ValueInput in,CallbackInfo ci) {
|
||||
double value=in.getDoubleOr("AstraContentSpeed",0); astra$speed=Double.isFinite(value) && value>0?Math.clamp(value,2,30):0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package online.astradev.content.mixin;
|
||||
|
||||
import net.minecraft.world.entity.projectile.EyeOfEnder;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import online.astradev.content.weapon.PayloadProjectile;
|
||||
import org.spongepowered.asm.mixin.*;
|
||||
import org.spongepowered.asm.mixin.injection.*;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin(EyeOfEnder.class)
|
||||
public abstract class PayloadMixin {
|
||||
@Shadow private boolean surviveAfterDeath;
|
||||
@Inject(method = "signalTo", at = @At("RETURN"))
|
||||
private void astra$noDuplicate(Vec3 target, CallbackInfo ci) {
|
||||
if (((EyeOfEnder)(Object)this).entityTags().contains(PayloadProjectile.NO_EYE_DROP)) surviveAfterDeath = false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package online.astradev.content.mixin;
|
||||
|
||||
import java.util.List;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.*;
|
||||
import net.minecraft.world.level.block.*;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.storage.loot.LootParams;
|
||||
import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
|
||||
import online.astradev.content.rail.Rails;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
|
||||
@Mixin(PoweredRailBlock.class)
|
||||
public abstract class RailBlockMixin extends BaseRailBlock {
|
||||
protected RailBlockMixin(boolean straight, Properties properties) { super(straight,properties); }
|
||||
@Override public void setPlacedBy(Level level, BlockPos pos, BlockState state, LivingEntity placer, ItemStack stack) {
|
||||
super.setPlacedBy(level,pos,state,placer,stack);
|
||||
if (state.is(Blocks.POWERED_RAIL) && level instanceof ServerLevel server) Rails.placed(server,pos,stack);
|
||||
}
|
||||
@Override protected List<ItemStack> getDrops(BlockState state, LootParams.Builder params) {
|
||||
var drops = super.getDrops(state,params); var origin = params.getOptionalParameter(LootContextParams.ORIGIN);
|
||||
if (!state.is(Blocks.POWERED_RAIL) || origin == null) return drops;
|
||||
var kind = Rails.loot(params.getLevel(),BlockPos.containing(origin));
|
||||
return kind == null ? drops : drops.stream().map(stack -> stack.is(asItem()) ? Rails.stack(kind,stack.getCount()) : stack).toList();
|
||||
}
|
||||
@Override protected ItemStack getCloneItemStack(LevelReader level, BlockPos pos, BlockState state, boolean includeData) {
|
||||
if (level instanceof ServerLevel server && state.is(Blocks.POWERED_RAIL)) {
|
||||
var kind=Rails.find(server,pos); if(kind!=null) return Rails.stack(kind,1);
|
||||
}
|
||||
return super.getCloneItemStack(level,pos,state,includeData);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package online.astradev.content.mixin;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.chunk.LevelChunk;
|
||||
import online.astradev.content.rail.Rails;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.*;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
@Mixin(LevelChunk.class)
|
||||
public abstract class RailChunkMixin {
|
||||
@Inject(method="setBlockState",at=@At("RETURN"))
|
||||
private void astra$changed(BlockPos pos,BlockState state,int flags,CallbackInfoReturnable<BlockState> cir) {
|
||||
if (((LevelChunk)(Object)this).getLevel() instanceof ServerLevel level) Rails.changed(level,pos,cir.getReturnValue(),state);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user