Skip to content

Commit

Permalink
Changed the farmable clay rule to a dispenser bahavior
Browse files Browse the repository at this point in the history
  • Loading branch information
RLLD576 committed Dec 10, 2023
1 parent dee0e08 commit 47cf321
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 4 deletions.
5 changes: 2 additions & 3 deletions src/main/java/net/rober/robercarpet/RoberCarpet.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import carpet.CarpetServer;
import carpet.settings.SettingsManager;
import net.fabricmc.api.ModInitializer;
import net.rober.robercarpet.register.dispenser.FarmableClayBehavior;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

Expand All @@ -18,9 +19,7 @@ public class RoberCarpet implements ModInitializer, CarpetExtension {

@Override
public void onInitialize() {
// This code runs as soon as Minecraft is in a mod-load-ready state.
// However, some things (like resources) may still be uninitialized.
// Proceed with mild caution.
FarmableClayBehavior.init();
RoberCarpet extension = new RoberCarpet();
CarpetServer.manageExtension(extension);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package net.rober.robercarpet.register.dispenser;

import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.DispenserBlock;
import net.minecraft.block.dispenser.FallibleItemDispenserBehavior;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.util.math.BlockPointer;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.rober.robercarpet.RoberCarpetSettings;

public class FarmableClayBehavior {
public static void init(){
DispenserBlock.registerBehavior(Items.POTION, new FallibleItemDispenserBehavior() {
@Override
public ItemStack dispenseSilently(BlockPointer pointer, ItemStack stack) {
if(!RoberCarpetSettings.FarmableClay)return super.dispenseSilently(pointer,stack);
World world = pointer.getWorld();
if (world.isClient) {
return super.dispenseSilently(pointer, stack);
}
if (pointer.getBlockState().getBlock() != Blocks.DISPENSER) {
return super.dispenseSilently(pointer,stack);
}
BlockPos targetPos = pointer.getPos().offset(pointer.getBlockState().get(DispenserBlock.FACING));
BlockState block_state = world.getBlockState(targetPos);
Block block = block_state.getBlock();
if(block==Blocks.DIRT){
world.setBlockState(targetPos,Blocks.CLAY.getDefaultState());
return new ItemStack(Items.GLASS_BOTTLE,1);
}
return super.dispenseSilently(pointer, stack);
}
});
}
}
1 change: 0 additions & 1 deletion src/main/resources/robercarpet.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"compatibilityLevel": "JAVA_16",
"mixins": [
"FallingBlockMixin",
"FarmableClayMixin",
"SleepingDelayMixin",
"ThunderWarnMixin"
],
Expand Down

0 comments on commit 47cf321

Please sign in to comment.