-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changed the farmable clay rule to a dispenser bahavior
- Loading branch information
Showing
3 changed files
with
42 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
src/main/java/net/rober/robercarpet/register/dispenser/FarmableClayBehavior.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters