support for lectern reading, moved item use on block to mixin
This commit is contained in:
parent
fdd9e2fb52
commit
78d7234785
@ -16,6 +16,7 @@ import net.minecraft.block.DoorBlock;
|
||||
import net.minecraft.block.FarmlandBlock;
|
||||
import net.minecraft.block.FenceGateBlock;
|
||||
import net.minecraft.block.JukeboxBlock;
|
||||
import net.minecraft.block.LecternBlock;
|
||||
import net.minecraft.block.LeverBlock;
|
||||
import net.minecraft.block.NetherPortalBlock;
|
||||
import net.minecraft.block.NoteBlock;
|
||||
|
@ -23,6 +23,8 @@ public enum EnumPermission {
|
||||
REDSTONE(Items.REDSTONE),
|
||||
JUKEBOX(Items.JUKEBOX),
|
||||
ITEMFRAMEROTATE(Items.ITEM_FRAME),
|
||||
LECTERNTAKE(Items.LECTERN),
|
||||
ENDCRYSTALPLACE(Items.END_CRYSTAL),
|
||||
TARGETBLOCK(Items.TARGET),
|
||||
PROJECTILES(Items.ARROW),
|
||||
TRAMPLE(Items.FARMLAND),
|
||||
|
@ -6,11 +6,16 @@ import com.flemmli97.flan.claim.EnumPermission;
|
||||
import com.flemmli97.flan.claim.BlockToPermissionMap;
|
||||
import com.flemmli97.flan.claim.PermHelper;
|
||||
import com.flemmli97.flan.config.ConfigHandler;
|
||||
import com.flemmli97.flan.gui.LockedLecternScreenHandler;
|
||||
import com.flemmli97.flan.player.EnumDisplayType;
|
||||
import com.flemmli97.flan.player.PlayerClaimData;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.DoorBlock;
|
||||
import net.minecraft.block.LecternBlock;
|
||||
import net.minecraft.block.entity.BlockEntity;
|
||||
import net.minecraft.block.entity.LecternBlockEntity;
|
||||
import net.minecraft.block.entity.LockableContainerBlockEntity;
|
||||
import net.minecraft.block.enums.DoubleBlockHalf;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.ItemEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
@ -31,7 +36,7 @@ import net.minecraft.world.World;
|
||||
public class BlockInteractEvents {
|
||||
|
||||
public static ActionResult breakBlocks(PlayerEntity p, World world, Hand hand, BlockPos pos, Direction dir) {
|
||||
if (world.isClient)
|
||||
if (world.isClient || p.isSpectator())
|
||||
return ActionResult.PASS;
|
||||
ServerPlayerEntity player = (ServerPlayerEntity) p;
|
||||
ClaimStorage storage = ClaimStorage.get((ServerWorld) world);
|
||||
@ -74,25 +79,33 @@ public class BlockInteractEvents {
|
||||
PlayerClaimData.get(player).addDisplayClaim(claim, EnumDisplayType.MAIN, player.getBlockPos().getY());
|
||||
return ActionResult.FAIL;
|
||||
}
|
||||
if(blockEntity instanceof LecternBlockEntity) {
|
||||
if (claim.canInteract(player, EnumPermission.LECTERNTAKE, hitResult.getBlockPos(), false))
|
||||
return ActionResult.PASS;
|
||||
LockedLecternScreenHandler.create(player, (LecternBlockEntity) blockEntity);
|
||||
return ActionResult.FAIL;
|
||||
}
|
||||
}
|
||||
EnumPermission perm = BlockToPermissionMap.getFromBlock(state.getBlock());
|
||||
if (perm != null) {
|
||||
//Pressureplate handled elsewhere
|
||||
if (perm!=null && perm != EnumPermission.PRESSUREPLATE) {
|
||||
if(claim.canInteract(player, perm, hitResult.getBlockPos(), true))
|
||||
return ActionResult.PASS;
|
||||
if(state.getBlock() instanceof DoorBlock){
|
||||
DoubleBlockHalf half = state.get(DoorBlock.HALF);
|
||||
if(half==DoubleBlockHalf.LOWER) {
|
||||
BlockState other = world.getBlockState(hitResult.getBlockPos().up());
|
||||
player.world.updateListeners(hitResult.getBlockPos().up(), other, other, 2);
|
||||
}
|
||||
else {
|
||||
BlockState other = world.getBlockState(hitResult.getBlockPos().down());
|
||||
player.world.updateListeners(hitResult.getBlockPos().down(), other, other, 2);
|
||||
}
|
||||
}
|
||||
PlayerClaimData.get(player).addDisplayClaim(claim, EnumDisplayType.MAIN, player.getBlockPos().getY());
|
||||
return ActionResult.FAIL;
|
||||
}
|
||||
}
|
||||
BlockPos placePos = hitResult.getBlockPos().offset(hitResult.getSide());
|
||||
claim = storage.getClaimAt(placePos);
|
||||
if(claim==null)
|
||||
return ActionResult.PASS;
|
||||
if (stack.getItem() instanceof BlockItem || stack.getItem() instanceof ToolItem || stack.getItem() == Items.ARMOR_STAND) {
|
||||
if(claim.canInteract(player, EnumPermission.PLACE, placePos, true))
|
||||
return ActionResult.PASS;
|
||||
PlayerClaimData.get(player).addDisplayClaim(claim, EnumDisplayType.MAIN, player.getBlockPos().getY());
|
||||
return ActionResult.FAIL;
|
||||
}
|
||||
}
|
||||
return ActionResult.PASS;
|
||||
}
|
||||
|
@ -46,7 +46,7 @@ public class EntityInteractEvents {
|
||||
}
|
||||
|
||||
public static ActionResult useAtEntity(PlayerEntity player, World world, Hand hand, Entity entity, /* Nullable */ EntityHitResult hitResult) {
|
||||
if (player.world.isClient)
|
||||
if (player.world.isClient || player.isSpectator())
|
||||
return ActionResult.PASS;
|
||||
ClaimStorage storage = ClaimStorage.get((ServerWorld) world);
|
||||
BlockPos pos = entity.getBlockPos();
|
||||
@ -61,7 +61,7 @@ public class EntityInteractEvents {
|
||||
}
|
||||
|
||||
public static ActionResult useEntity(PlayerEntity p, World world, Hand hand, Entity entity) {
|
||||
if(p.world.isClient)
|
||||
if(p.world.isClient || p.isSpectator())
|
||||
return ActionResult.PASS;
|
||||
ServerPlayerEntity player = (ServerPlayerEntity) p;
|
||||
ClaimStorage storage = ClaimStorage.get((ServerWorld) world);
|
||||
@ -150,7 +150,7 @@ public class EntityInteractEvents {
|
||||
}
|
||||
|
||||
public static ActionResult attackSimple(PlayerEntity p, Entity entity, boolean message) {
|
||||
if (p.world.isClient)
|
||||
if (p.world.isClient || p.isSpectator())
|
||||
return ActionResult.PASS;
|
||||
if (entity instanceof Monster)
|
||||
return ActionResult.PASS;
|
||||
|
@ -8,14 +8,24 @@ import com.flemmli97.flan.config.ConfigHandler;
|
||||
import com.flemmli97.flan.player.EnumDisplayType;
|
||||
import com.flemmli97.flan.player.EnumEditMode;
|
||||
import com.flemmli97.flan.player.PlayerClaimData;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.LecternBlock;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.BlockItem;
|
||||
import net.minecraft.item.BucketItem;
|
||||
import net.minecraft.item.EndCrystalItem;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.ItemUsageContext;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.item.ToolItem;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.server.network.ServerPlayerInteractionManager;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.Formatting;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.TypedActionResult;
|
||||
@ -29,7 +39,7 @@ import java.util.Set;
|
||||
public class ItemInteractEvents {
|
||||
|
||||
public static TypedActionResult<ItemStack> useItem(PlayerEntity p, World world, Hand hand) {
|
||||
if (world.isClient)
|
||||
if (world.isClient || p.isSpectator())
|
||||
return TypedActionResult.pass(p.getStackInHand(hand));
|
||||
ServerPlayerEntity player = (ServerPlayerEntity) p;
|
||||
ItemStack stack = player.getStackInHand(hand);
|
||||
@ -61,6 +71,31 @@ public class ItemInteractEvents {
|
||||
return TypedActionResult.pass(stack);
|
||||
}
|
||||
|
||||
private static Set<Item> blackListedItems = Sets.newHashSet(Items.COMPASS, Items.FILLED_MAP, Items.FIREWORK_ROCKET);
|
||||
public static ActionResult onItemUseBlock(ItemUsageContext context){
|
||||
if(context.getWorld().isClient || context.getStack().isEmpty())
|
||||
return ActionResult.PASS;
|
||||
ClaimStorage storage = ClaimStorage.get((ServerWorld) context.getWorld());
|
||||
BlockPos placePos = context.getBlockPos().offset(context.getSide());
|
||||
Claim claim = storage.getClaimAt(placePos);
|
||||
if(claim==null)
|
||||
return ActionResult.PASS;
|
||||
if(blackListedItems.contains(context.getStack().getItem()))
|
||||
return ActionResult.PASS;
|
||||
ServerPlayerEntity player = (ServerPlayerEntity) context.getPlayer();
|
||||
if(context.getStack().getItem() == Items.END_CRYSTAL) {
|
||||
if(claim.canInteract(player, EnumPermission.ENDCRYSTALPLACE, placePos, true))
|
||||
return ActionResult.PASS;
|
||||
return ActionResult.FAIL;
|
||||
}
|
||||
if(claim.canInteract(player, EnumPermission.PLACE, placePos, true))
|
||||
return ActionResult.PASS;
|
||||
BlockState other = context.getWorld().getBlockState(placePos.up());
|
||||
player.world.updateListeners(placePos.up(), other, other, 2);
|
||||
PlayerClaimData.get(player).addDisplayClaim(claim, EnumDisplayType.MAIN, player.getBlockPos().getY());
|
||||
return ActionResult.FAIL;
|
||||
}
|
||||
|
||||
private static boolean cantClaimInWorld(ServerWorld world){
|
||||
for(String s : ConfigHandler.config.blacklistedWorlds){
|
||||
if(s.equals(world.getRegistryKey().getValue().toString())) {
|
||||
|
@ -0,0 +1,49 @@
|
||||
package com.flemmli97.flan.gui;
|
||||
|
||||
import com.flemmli97.flan.claim.Claim;
|
||||
import com.flemmli97.flan.claim.PermHelper;
|
||||
import com.flemmli97.flan.config.ConfigHandler;
|
||||
import com.flemmli97.flan.mixin.ILecternBlockValues;
|
||||
import net.minecraft.block.LecternBlock;
|
||||
import net.minecraft.block.entity.LecternBlockEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.inventory.Inventory;
|
||||
import net.minecraft.screen.LecternScreenHandler;
|
||||
import net.minecraft.screen.NamedScreenHandlerFactory;
|
||||
import net.minecraft.screen.PropertyDelegate;
|
||||
import net.minecraft.screen.ScreenHandler;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.Formatting;
|
||||
|
||||
public class LockedLecternScreenHandler extends LecternScreenHandler {
|
||||
|
||||
public LockedLecternScreenHandler(int syncId, Inventory inventory, PropertyDelegate propertyDelegate) {
|
||||
super(syncId, inventory, propertyDelegate);
|
||||
}
|
||||
|
||||
public static void create(ServerPlayerEntity player, LecternBlockEntity lectern) {
|
||||
NamedScreenHandlerFactory fac = new NamedScreenHandlerFactory() {
|
||||
@Override
|
||||
public ScreenHandler createMenu(int syncId, PlayerInventory inv, PlayerEntity player) {
|
||||
return new LockedLecternScreenHandler(syncId, ((ILecternBlockValues)lectern).getInv(), ((ILecternBlockValues)lectern).getProp());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Text getDisplayName() {
|
||||
return lectern.getDisplayName();
|
||||
}
|
||||
};
|
||||
player.openHandledScreen(fac);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onButtonClick(PlayerEntity player, int id) {
|
||||
if(id==3) {
|
||||
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.noPermissionSimple, Formatting.DARK_RED), false);
|
||||
return false;
|
||||
}
|
||||
return super.onButtonClick(player, id);
|
||||
}
|
||||
}
|
@ -13,7 +13,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
import java.util.List;
|
||||
|
||||
@Mixin(Explosion.class)
|
||||
public class ExplosionMixin {
|
||||
public abstract class ExplosionMixin {
|
||||
|
||||
@Shadow
|
||||
private List<BlockPos> affectedBlocks;
|
||||
|
@ -0,0 +1,20 @@
|
||||
package com.flemmli97.flan.mixin;
|
||||
|
||||
import net.minecraft.block.entity.LecternBlockEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.inventory.Inventory;
|
||||
import net.minecraft.screen.PropertyDelegate;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.gen.Accessor;
|
||||
|
||||
@Mixin(LecternBlockEntity.class)
|
||||
public interface ILecternBlockValues {
|
||||
|
||||
@Accessor("inventory")
|
||||
public Inventory getInv();
|
||||
|
||||
@Accessor("propertyDelegate")
|
||||
public PropertyDelegate getProp();
|
||||
}
|
23
src/main/java/com/flemmli97/flan/mixin/ItemStackMixin.java
Normal file
23
src/main/java/com/flemmli97/flan/mixin/ItemStackMixin.java
Normal file
@ -0,0 +1,23 @@
|
||||
package com.flemmli97.flan.mixin;
|
||||
|
||||
import com.flemmli97.flan.event.ItemInteractEvents;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.ItemUsageContext;
|
||||
import net.minecraft.util.ActionResult;
|
||||
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;
|
||||
|
||||
@Mixin(ItemStack.class)
|
||||
public abstract class ItemStackMixin {
|
||||
|
||||
@Inject(method = "useOnBlock", at = @At(value = "HEAD"), cancellable = true)
|
||||
public void blockUse(ItemUsageContext context, CallbackInfoReturnable<ActionResult> info){
|
||||
ActionResult result = ItemInteractEvents.onItemUseBlock(context);
|
||||
if (result != ActionResult.PASS) {
|
||||
info.setReturnValue(result);
|
||||
info.cancel();
|
||||
}
|
||||
}
|
||||
}
|
@ -10,7 +10,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
@Mixin(LivingEntity.class)
|
||||
public class LivingEntityMixin {
|
||||
public abstract class LivingEntityMixin {
|
||||
|
||||
@Inject(method = "damage", at = @At(value = "HEAD"), cancellable = true)
|
||||
public void onDamage(DamageSource source, float amount, CallbackInfoReturnable<Boolean> info){
|
||||
|
@ -11,7 +11,7 @@ import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin(TurtleEggBlock.class)
|
||||
public class TurtleEggMixin {
|
||||
public abstract class TurtleEggMixin {
|
||||
|
||||
@Inject(method = "onSteppedOn", at = @At(value = "HEAD"), cancellable = true)
|
||||
public void collision(World world, BlockPos pos, Entity entity, CallbackInfo info) {
|
||||
|
@ -9,7 +9,7 @@ import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin(WitherEntity.class)
|
||||
public class WitherMixin {
|
||||
public abstract class WitherMixin {
|
||||
|
||||
@Shadow
|
||||
private int field_7082;
|
||||
|
@ -16,7 +16,9 @@
|
||||
"ExplosionMixin",
|
||||
"EnderPearlEntityMixin",
|
||||
"IPersistentProjectileVars",
|
||||
"LivingEntityMixin"
|
||||
"LivingEntityMixin",
|
||||
"ItemStackMixin",
|
||||
"ILecternBlockValues"
|
||||
],
|
||||
"server": [
|
||||
],
|
||||
|
Loading…
Reference in New Issue
Block a user