- 75
- 1
- 2
Взял из открытых исходников одного мода миксины для блока и ентити костра. В том моде все работает, но при переносе в мой - костер все так же остается ванильным костром. Подскажите, как исправить? Код с миксинов прилагаю
CampfireBlockMixin:
@Mixin(CampfireBlock.class)
public abstract class CampfireBlockMixin extends BaseEntityBlock {
protected CampfireBlockMixin(Properties builder) {
super(builder);
}
@Inject(at = @At("RETURN"), method = "<init>*")
protected void initProxy(boolean spawnParticles, int fireDamage, BlockBehaviour.Properties properties, CallbackInfo info) {
this.registerDefaultState(this.defaultBlockState().setValue(CampfireBlock.LIT, false));
}
@Inject(at = @At("RETURN"), method = "getStateForPlacement", cancellable = true)
protected void getStateForPlacementProxy(BlockPlaceContext context, CallbackInfoReturnable<BlockState> cir) {
if (cir.getReturnValue() != null) {
cir.setReturnValue(cir.getReturnValue().setValue(CampfireBlock.LIT, false));
cir.cancel();
}
}
@Intrinsic(displace = true)
public void id$animateTick(@Nonnull BlockState stateIn, Level worldIn, BlockPos pos, @Nonnull Random rand) {
int particleFactor = 1;
if (worldIn.isRainingAt(pos.above())) {
particleFactor = 2;
}
for (int i = 0; i < particleFactor; i++) {
this.animateTick(stateIn, worldIn, pos, rand);
}
}
}
CampfireTileEntityMixin:
@Mixin(CampfireBlockEntity.class)
public abstract class CampfireTileEntityMixin extends BlockEntity {
private Boolean isSoulCampfire;
private int litTime = 0;
private int rainTime = 0;
public CampfireTileEntityMixin(BlockPos pos, BlockState state) {
super(BlockEntityType.CAMPFIRE, pos, state);
}
private boolean isSoulCampfire() {
if (isSoulCampfire == null) {
if (this.level != null) {
isSoulCampfire = this.level.getBlockState(this.worldPosition).getBlock() == Blocks.SOUL_CAMPFIRE;
return isSoulCampfire;
}
return false;
}
return isSoulCampfire;
}
private int getMaxLitTime() {
return 2000;
}
private boolean dropsItemsWhenUnlitByTimeOrRain() {
return true;
}
private boolean breaksWhenUnlitByTime() {
return true;
}
private int getRainUnlitTime() {
return 500;
}
private int getParticleFactorDuringRain() {
return 2;
}
private void playUnlitSound() {
if (this.level != null && !this.level.isClientSide()) {
this.level.levelEvent(null, 1009, this.getBlockPos(), 0);
}
}
private void dropAllContainingItems() {
if (this.level != null) {
CampfireBlock.dowse(null, this.level, this.getBlockPos(), this.getBlockState());
}
}
private void destroyCampfire() {
if (this.level != null) {
this.playUnlitSound();
this.dropAllContainingItems();
this.level.setBlockAndUpdate(this.getBlockPos(), Blocks.AIR.defaultBlockState());
}
}
private void unlitCampfire() {
if (this.level != null) {
this.playUnlitSound();
if (this.dropsItemsWhenUnlitByTimeOrRain()) {
this.dropAllContainingItems();
}
this.level.setBlockAndUpdate(this.getBlockPos(), this.getBlockState().setValue(CampfireBlock.LIT, false));
this.litTime = 0;
}
}
@Inject(at = @At("RETURN"), method = "cookTick")
private static void cookTickProxy(Level level, BlockPos pos, BlockState state, CampfireBlockEntity blockEntity, CallbackInfo info) {
CampfireTileEntityMixin mixinEntity = (CampfireTileEntityMixin) (BlockEntity) blockEntity;
if (level != null) {
if (state.getValue(CampfireBlock.LIT)) {
//if lit time is active
int maxLitTime = mixinEntity.getMaxLitTime();
if (maxLitTime > 0) {
mixinEntity.litTime++;
if (mixinEntity.litTime >= maxLitTime) {
if (mixinEntity.breaksWhenUnlitByTime()) {
mixinEntity.destroyCampfire();
} else {
mixinEntity.unlitCampfire();
}
return; //fixes destroying while raining
}
}
if (level.isRainingAt(pos.above())) {
//if rain should unlit a campfire and it is raining there
int rainUnlitTime = mixinEntity.getRainUnlitTime();
if (rainUnlitTime >= 0) {
mixinEntity.rainTime++;
if (mixinEntity.rainTime >= rainUnlitTime) {
mixinEntity.rainTime = 0;
mixinEntity.unlitCampfire();
}
} else {
mixinEntity.rainTime = 0;
}
}
} else {
mixinEntity.litTime = 0;
}
}
}
@Inject(at = @At("RETURN"), method = "particleTick")
private static void particleTickProxy(Level level, BlockPos pos, BlockState state, CampfireBlockEntity blockEntity, CallbackInfo info) {
CampfireTileEntityMixin mixinEntity = (CampfireTileEntityMixin) (BlockEntity) blockEntity;
//during rain the campfire has more particles (if activated)
int particleFactor = mixinEntity.getParticleFactorDuringRain();
if (level != null && level.isClientSide && particleFactor > 1 && level.isRainingAt(pos.above())) {
for (int i = 0; i < particleFactor - 1; i++) {
CampfireBlock.makeParticles(level, pos, state.getValue(CampfireBlock.SIGNAL_FIRE), false);
}
}
}
@Inject(at = @At("RETURN"), method = "load")
protected void loadProxy(CompoundTag nbtIn, CallbackInfo info) {
if (nbtIn.contains("CampfireLitTime")) {
this.litTime = nbtIn.getInt("CampfireLitTime");
}
}
@Inject(at = @At("RETURN"), method = "saveAdditional")
protected void saveAdditionalProxy(CompoundTag compound, CallbackInfo info) {
if (compound != null) {
compound.putInt("CampfireLitTime", this.litTime);
}
}
}