cactus and block rotator
This commit is contained in:
1 parent
fa2ff94258
commit
e9d2be34c0
9 files changed
+209
-30
No files matched your search
@@ -0,0 +1,25 @@
|
||||
package carpet.mixins;
|
||||
|
||||
import carpet.helpers.BlockRotator;
|
||||
import net.minecraft.Bootstrap;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.block.DispenserBlock;
|
||||
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;
|
||||
|
||||
@Mixin(Bootstrap.class)
|
||||
public abstract class Bootstrap_cactusMixin
|
||||
{
|
||||
@Inject(method = "initialize", at = @At(
|
||||
value = "INVOKE",
|
||||
target = "Lnet/minecraft/block/dispenser/DispenserBehavior;registerDefaults()V",
|
||||
shift = At.Shift.AFTER
|
||||
))
|
||||
private static void registerCactus(CallbackInfo ci)
|
||||
{
|
||||
DispenserBlock.registerBehavior(Blocks.CACTUS.asItem(), new BlockRotator.CactusDispenserBehaviour());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package carpet.mixins;
|
||||
|
||||
import carpet.CarpetSettings;
|
||||
import carpet.fakes.EntityInterface;
|
||||
import carpet.helpers.BlockRotator;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
@@ -12,15 +13,31 @@ import org.spongepowered.asm.mixin.injection.Redirect;
|
||||
public abstract class DirectionMixin
|
||||
{
|
||||
@Redirect(method = "getEntityFacingOrder", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;getYaw(F)F"))
|
||||
private static float ifGetYaw(Entity entity, float float_1)
|
||||
private static float getYaw(Entity entity, float float_1)
|
||||
{
|
||||
float yaw;
|
||||
if (!CarpetSettings.getBool("placementRotationFix"))
|
||||
{
|
||||
return entity.getYaw(1.0F);
|
||||
yaw = entity.getYaw(float_1);
|
||||
}
|
||||
else
|
||||
{
|
||||
return ((EntityInterface) entity).getMainYaw(1.0F);
|
||||
yaw = ((EntityInterface) entity).getMainYaw(float_1);
|
||||
}
|
||||
if (BlockRotator.flippinEligibility(entity))
|
||||
{
|
||||
yaw += 180f;
|
||||
}
|
||||
return yaw;
|
||||
}
|
||||
@Redirect(method = "getEntityFacingOrder", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;getPitch(F)F"))
|
||||
private static float getPitch(Entity entity, float float_1)
|
||||
{
|
||||
float pitch = entity.getPitch(float_1);
|
||||
if (BlockRotator.flippinEligibility(entity))
|
||||
{
|
||||
pitch = -pitch;
|
||||
}
|
||||
return pitch;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package carpet.mixins;
|
||||
|
||||
import carpet.helpers.BlockRotator;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.block.DispenserBlock;
|
||||
import net.minecraft.block.dispenser.DispenserBehavior;
|
||||
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;
|
||||
|
||||
//UNUSED - used Bootstrap_cactus instead cause mixins
|
||||
@Mixin(DispenserBehavior.class)
|
||||
public interface DispenserBehaviour_cactusMixin
|
||||
{
|
||||
@Inject(method = "registerDefaults", at = @At("HEAD"))
|
||||
static void addBlockRotator(CallbackInfo ci)
|
||||
{
|
||||
DispenserBlock.registerBehavior(Blocks.CACTUS.asItem(), new BlockRotator.CactusDispenserBehaviour());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package carpet.mixins;
|
||||
|
||||
import carpet.helpers.BlockRotator;
|
||||
import net.minecraft.block.HopperBlock;
|
||||
import net.minecraft.item.ItemPlacementContext;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||
|
||||
@Mixin(HopperBlock.class)
|
||||
public class HopperBlock_cactusMixin
|
||||
{
|
||||
@Redirect(method = "getPlacementState", at = @At(
|
||||
value = "INVOKE",
|
||||
target = "Lnet/minecraft/item/ItemPlacementContext;getSide()Lnet/minecraft/util/math/Direction;"
|
||||
))
|
||||
private Direction getOppositeOpposite(ItemPlacementContext context)
|
||||
{
|
||||
if (BlockRotator.flippinEligibility(context.getPlayer()))
|
||||
{
|
||||
return context.getSide().getOpposite();
|
||||
}
|
||||
return context.getSide();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package carpet.mixins;
|
||||
|
||||
import carpet.helpers.BlockRotator;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemUsageContext;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||
|
||||
@Mixin(ItemUsageContext.class)
|
||||
public class ItemUsageContext_cactusMixin
|
||||
{
|
||||
@Redirect(method = "getPlayerFacing", at = @At(
|
||||
value = "INVOKE",
|
||||
target = "Lnet/minecraft/entity/player/PlayerEntity;getHorizontalFacing()Lnet/minecraft/util/math/Direction;"
|
||||
))
|
||||
private Direction getPlayerFacing(PlayerEntity playerEntity)
|
||||
{
|
||||
Direction dir = playerEntity.getHorizontalFacing();
|
||||
if (BlockRotator.flippinEligibility(playerEntity))
|
||||
{
|
||||
dir = dir.getOpposite();
|
||||
}
|
||||
return dir;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package carpet.mixins;
|
||||
|
||||
import carpet.helpers.BlockRotator;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.server.network.ServerPlayerInteractionManager;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.hit.BlockHitResult;
|
||||
import net.minecraft.world.World;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||
|
||||
@Mixin(ServerPlayerInteractionManager.class)
|
||||
public class ServerPlayerInteractionManager_cactusMixin
|
||||
{
|
||||
|
||||
@Redirect(method = "interactBlock", at = @At(
|
||||
value = "INVOKE",
|
||||
target = "Lnet/minecraft/block/BlockState;activate(Lnet/minecraft/world/World;Lnet/minecraft/entity/player/PlayerEntity;Lnet/minecraft/util/Hand;Lnet/minecraft/util/hit/BlockHitResult;)Z"
|
||||
))
|
||||
private boolean activateWithOptionalCactus(BlockState blockState, World world_1, PlayerEntity playerEntity_1, Hand hand_1, BlockHitResult blockHitResult_1)
|
||||
{
|
||||
Boolean flipped = BlockRotator.flipBlockWithCactus(blockState, world_1, playerEntity_1, hand_1, blockHitResult_1);
|
||||
if (flipped)
|
||||
return true;
|
||||
|
||||
return blockState.activate(world_1, playerEntity_1, hand_1, blockHitResult_1);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user