Skip to content

Commit

Permalink
Add splashOxidize rule
Browse files Browse the repository at this point in the history
  • Loading branch information
RubixDev committed Jun 27, 2022
1 parent 74bbf89 commit 7da491f
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/main/java/de/rubixdev/rug/RugSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -1256,6 +1256,12 @@ public String description() {
category = { SURVIVAL, CRAFTING, BUGFIX, RUG }
)
public static boolean missingCobbleRecipes = false;

@Rule(
desc = "Copper blocks oxidize one stage when hit with a water bottle",
category = { FEATURE, DISPENSER, SURVIVAL, RUG }
)
public static boolean splashOxidize = false;
}

// BUGFIX
Expand Down
35 changes: 35 additions & 0 deletions src/main/java/de/rubixdev/rug/mixins/PotionEntityMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package de.rubixdev.rug.mixins;

import de.rubixdev.rug.RugSettings;
import net.minecraft.block.*;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.projectile.thrown.PotionEntity;
import net.minecraft.entity.projectile.thrown.ThrownEntity;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import java.util.Optional;

@Mixin(PotionEntity.class)
public abstract class PotionEntityMixin extends ThrownEntity {
protected PotionEntityMixin(EntityType<? extends ThrownEntity> entityType, World world) {
super(entityType, world);
}

@Inject(method = "onBlockHit", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/projectile/thrown/PotionEntity;extinguishFire(Lnet/minecraft/util/math/BlockPos;)V", ordinal = 0))
private void ageCopper(BlockHitResult blockHitResult, CallbackInfo ci) {
BlockPos blockPos = blockHitResult.getBlockPos();
BlockState blockState = this.world.getBlockState(blockPos);
Block block = blockState.getBlock();

if (block instanceof Oxidizable && RugSettings.splashOxidize) {
Optional<BlockState> oxidized = ((Oxidizable) block).getDegradationResult(blockState);
oxidized.ifPresent(state -> this.world.setBlockState(blockPos, state));
}
}
}
1 change: 1 addition & 0 deletions src/main/resources/rug.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"PistonHandlerMixin",
"PlayerEntityMixin",
"PointedDripstoneBlockMixin",
"PotionEntityMixin",
"PressurePlateBlockMixin",
"RedstoneLampBlockMixin",
"RepeaterBlockMixin",
Expand Down

0 comments on commit 7da491f

Please sign in to comment.