mirror of
https://github.com/Sollace/Unicopia.git
synced 2024-11-27 15:17:59 +01:00
Make beds waterlog
This commit is contained in:
parent
917af90f37
commit
c656eb2309
3 changed files with 27 additions and 2 deletions
|
@ -1,12 +1,18 @@
|
||||||
package com.minelittlepony.unicopia.mixin;
|
package com.minelittlepony.unicopia.mixin;
|
||||||
|
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
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.CallbackInfoReturnable;
|
||||||
|
|
||||||
import com.minelittlepony.unicopia.item.toxin.ToxicHolder;
|
import com.minelittlepony.unicopia.item.toxin.ToxicHolder;
|
||||||
|
import com.minelittlepony.unicopia.server.world.WaterLoggingManager;
|
||||||
|
|
||||||
|
import net.minecraft.block.BlockState;
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
import net.minecraft.item.BlockItem;
|
import net.minecraft.item.BlockItem;
|
||||||
import net.minecraft.item.Item;
|
import net.minecraft.item.Item;
|
||||||
|
import net.minecraft.item.ItemPlacementContext;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.util.Hand;
|
import net.minecraft.util.Hand;
|
||||||
import net.minecraft.util.TypedActionResult;
|
import net.minecraft.util.TypedActionResult;
|
||||||
|
@ -28,4 +34,9 @@ abstract class MixinBlockItem extends Item implements ToxicHolder {
|
||||||
.map(t -> t.use(world, player, hand))
|
.map(t -> t.use(world, player, hand))
|
||||||
.orElseGet(() -> super.use(world, player, hand));
|
.orElseGet(() -> super.use(world, player, hand));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Inject(method = "getPlacementState", at = @At("RETURN"), cancellable = true)
|
||||||
|
private void onGetPlacementState(ItemPlacementContext context, CallbackInfoReturnable<BlockState> info) {
|
||||||
|
WaterLoggingManager.getInstance().getPlacementState(context, info);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,4 +69,4 @@ abstract class MixinBlockState extends State<Block, BlockState> {
|
||||||
private void onGetStateForNeighborUpdate(Direction direction, BlockState neighborState, WorldAccess world, BlockPos pos, BlockPos neighborPos, CallbackInfoReturnable<BlockState> info) {
|
private void onGetStateForNeighborUpdate(Direction direction, BlockState neighborState, WorldAccess world, BlockPos pos, BlockPos neighborPos, CallbackInfoReturnable<BlockState> info) {
|
||||||
WaterLoggingManager.<Block, BlockState>getInstance().getUpdatedState(world, pos, asBlockState(), info);
|
WaterLoggingManager.<Block, BlockState>getInstance().getUpdatedState(world, pos, asBlockState(), info);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,8 @@ import net.minecraft.block.*;
|
||||||
import net.minecraft.block.enums.DoubleBlockHalf;
|
import net.minecraft.block.enums.DoubleBlockHalf;
|
||||||
import net.minecraft.fluid.FluidState;
|
import net.minecraft.fluid.FluidState;
|
||||||
import net.minecraft.fluid.Fluids;
|
import net.minecraft.fluid.Fluids;
|
||||||
|
import net.minecraft.item.ItemPlacementContext;
|
||||||
|
import net.minecraft.registry.tag.FluidTags;
|
||||||
import net.minecraft.state.State;
|
import net.minecraft.state.State;
|
||||||
import net.minecraft.state.property.Properties;
|
import net.minecraft.state.property.Properties;
|
||||||
import net.minecraft.state.property.Property;
|
import net.minecraft.state.property.Property;
|
||||||
|
@ -35,11 +37,22 @@ public class WaterLoggingManager<O, S extends State<O, S>> {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void getDefaultState(O owner, CallbackInfoReturnable<S> info) {
|
public void getDefaultState(O owner, CallbackInfoReturnable<S> info) {
|
||||||
|
if (owner instanceof BedBlock) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (appliesTo(owner, info.getReturnValue())) {
|
if (appliesTo(owner, info.getReturnValue())) {
|
||||||
info.setReturnValue(info.getReturnValue().with(Properties.WATERLOGGED, true));
|
info.setReturnValue(info.getReturnValue().with(Properties.WATERLOGGED, true));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public void getPlacementState(ItemPlacementContext context, CallbackInfoReturnable<BlockState> info) {
|
||||||
|
BlockState state = info.getReturnValue();
|
||||||
|
if (state != null && appliesTo((O)state.getBlock(), (S)state)) {
|
||||||
|
info.setReturnValue(state.with(Properties.WATERLOGGED, context.getWorld().getFluidState(context.getBlockPos()).isIn(FluidTags.WATER)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void getFluidState(O owner, S state, CallbackInfoReturnable<FluidState> info) {
|
public void getFluidState(O owner, S state, CallbackInfoReturnable<FluidState> info) {
|
||||||
if (appliesTo(owner, state)) {
|
if (appliesTo(owner, state)) {
|
||||||
info.setReturnValue((state.get(Properties.WATERLOGGED) ? Fluids.WATER : Fluids.EMPTY).getDefaultState());
|
info.setReturnValue((state.get(Properties.WATERLOGGED) ? Fluids.WATER : Fluids.EMPTY).getDefaultState());
|
||||||
|
@ -61,7 +74,8 @@ public class WaterLoggingManager<O, S extends State<O, S>> {
|
||||||
&& (block instanceof SeagrassBlock
|
&& (block instanceof SeagrassBlock
|
||||||
|| block instanceof TallSeagrassBlock
|
|| block instanceof TallSeagrassBlock
|
||||||
|| block instanceof KelpBlock
|
|| block instanceof KelpBlock
|
||||||
|| block instanceof KelpPlantBlock);
|
|| block instanceof KelpPlantBlock
|
||||||
|
|| block instanceof BedBlock);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean shouldPreventRemoval(WorldAccess world, BlockPos pos, AbstractBlock.AbstractBlockState oldState, AbstractBlock.AbstractBlockState newState) {
|
public boolean shouldPreventRemoval(WorldAccess world, BlockPos pos, AbstractBlock.AbstractBlockState oldState, AbstractBlock.AbstractBlockState newState) {
|
||||||
|
|
Loading…
Reference in a new issue