use of com.minecolonies.api.blocks.AbstractBlockHut in project minecolonies by Minecolonies.
the class AbstractBuildingContainer method registerBlockPosition.
@Override
@SuppressWarnings("squid:S1172")
public void registerBlockPosition(@NotNull final Block block, @NotNull final BlockPos pos, @NotNull final World world) {
if (block instanceof AbstractBlockHut) {
final TileEntity entity = world.getBlockEntity(pos);
if (entity instanceof TileEntityColonyBuilding) {
((TileEntityColonyBuilding) entity).setStyle(this.getStyle());
((TileEntityColonyBuilding) entity).setMirror(isMirrored());
final IBuilding building = colony.getBuildingManager().getBuilding(pos);
if (building != null) {
building.setStyle(this.getStyle());
building.setParent(getID());
addChild(pos);
}
}
} else if (block instanceof BlockMinecoloniesRack) {
addContainerPosition(pos);
if (block instanceof BlockMinecoloniesRack) {
final TileEntity entity = world.getBlockEntity(pos);
if (entity instanceof TileEntityRack) {
((TileEntityRack) entity).setBuildingPos(this.getID());
}
}
}
}
use of com.minecolonies.api.blocks.AbstractBlockHut in project minecolonies by ldtteam.
the class ColonyPermissionEventHandler method on.
/**
* PlayerInteractEvent handler.
* <p>
* Check, if a player right clicked a block. Deny if: - If the block is in colony - block is AbstractBlockHut - player has not permission
*
* @param event PlayerInteractEvent
*/
@SubscribeEvent
public void on(final PlayerInteractEvent event) {
if (colony.isCoordInColony(event.getWorld(), event.getPos()) && !(event instanceof PlayerInteractEvent.EntityInteract || event instanceof PlayerInteractEvent.EntityInteractSpecific)) {
final Block block = event.getWorld().getBlockState(event.getPos()).getBlock();
// Huts
if (event instanceof PlayerInteractEvent.RightClickBlock && block instanceof AbstractBlockHut && !colony.getPermissions().hasPermission(event.getPlayer(), Action.ACCESS_HUTS)) {
cancelEvent(event, event.getPlayer(), colony, Action.ACCESS_HUTS, event.getPos());
return;
}
final Permissions perms = colony.getPermissions();
if (isFreeToInteractWith(block, event.getPos()) && perms.hasPermission(event.getPlayer(), Action.ACCESS_FREE_BLOCKS)) {
return;
}
if (MineColonies.getConfig().getServer().enableColonyProtection.get()) {
if (!perms.hasPermission(event.getPlayer(), Action.RIGHTCLICK_BLOCK) && !(block instanceof AirBlock)) {
checkEventCancelation(Action.RIGHTCLICK_BLOCK, event.getPlayer(), event.getWorld(), event, event.getPos());
return;
}
if (block instanceof ContainerBlock && !perms.hasPermission(event.getPlayer(), Action.OPEN_CONTAINER)) {
cancelEvent(event, event.getPlayer(), colony, Action.OPEN_CONTAINER, event.getPos());
return;
}
if (event.getWorld().getBlockEntity(event.getPos()) != null && !perms.hasPermission(event.getPlayer(), Action.RIGHTCLICK_ENTITY)) {
checkEventCancelation(Action.RIGHTCLICK_ENTITY, event.getPlayer(), event.getWorld(), event, event.getPos());
return;
}
final ItemStack stack = event.getItemStack();
if (ItemStackUtils.isEmpty(stack) || stack.getItem().isEdible()) {
return;
}
if (stack.getItem() instanceof PotionItem) {
checkEventCancelation(Action.THROW_POTION, event.getPlayer(), event.getWorld(), event, event.getPos());
return;
}
if (stack.getItem() instanceof ItemScanTool && !perms.hasPermission(event.getPlayer(), Action.USE_SCAN_TOOL)) {
cancelEvent(event, event.getPlayer(), colony, Action.USE_SCAN_TOOL, event.getPos());
}
}
}
}
use of com.minecolonies.api.blocks.AbstractBlockHut in project minecolonies by ldtteam.
the class ColonyPermissionEventHandler method on.
/**
* BlockEvent.BreakEvent handler.
*
* @param event BlockEvent.BreakEvent
*/
@SubscribeEvent
public void on(final BlockEvent.BreakEvent event) {
final IWorld world = event.getWorld();
if (!MineColonies.getConfig().getServer().enableColonyProtection.get() || world.isClientSide()) {
return;
}
if (event.getState().getBlock() instanceof AbstractBlockHut) {
@Nullable final IBuilding building = IColonyManager.getInstance().getBuilding(event.getPlayer().level, event.getPos());
if (building == null) {
return;
}
if (event.getState().getBlock() == ModBlocks.blockHutTownHall && !((BlockHutTownHall) event.getState().getBlock()).getValidBreak() && !event.getPlayer().isCreative()) {
cancelEvent(event, event.getPlayer(), colony, Action.BREAK_HUTS, event.getPos());
return;
}
if (!building.getColony().getPermissions().hasPermission(event.getPlayer(), Action.BREAK_HUTS)) {
if (checkEventCancelation(Action.BREAK_HUTS, event.getPlayer(), event.getPlayer().getCommandSenderWorld(), event, event.getPos())) {
return;
}
}
building.destroy();
if (MineColonies.getConfig().getServer().pvp_mode.get() && event.getState().getBlock() == ModBlocks.blockHutTownHall) {
IColonyManager.getInstance().deleteColonyByWorld(building.getColony().getID(), false, event.getPlayer().level);
}
} else {
checkEventCancelation(Action.BREAK_BLOCKS, event.getPlayer(), event.getPlayer().getCommandSenderWorld(), event, event.getPos());
}
}
use of com.minecolonies.api.blocks.AbstractBlockHut in project minecolonies by ldtteam.
the class EventHandler method onPlayerInteract.
/**
* Event when a player right clicks a block, or right clicks with an item. Event gets cancelled when player has no permission. Event gets cancelled when the player has no
* permission to place a hut, and tried it.
*
* @param event {@link PlayerInteractEvent.RightClickBlock}
*/
@SubscribeEvent
public static void onPlayerInteract(@NotNull final PlayerInteractEvent.RightClickBlock event) {
final PlayerEntity player = event.getPlayer();
final World world = event.getWorld();
BlockPos bedBlockPos = event.getPos();
// and uses that return value, but I didn't want to call it twice
if (playerRightClickInteract(player, world, event.getPos()) && world.getBlockState(event.getPos()).getBlock() instanceof AbstractBlockHut) {
final IColony colony = IColonyManager.getInstance().getIColony(world, event.getPos());
if (colony != null && !colony.getPermissions().hasPermission(player, Action.ACCESS_HUTS)) {
event.setCanceled(true);
}
return;
} else if ("pmardle".equalsIgnoreCase(event.getPlayer().getName().getString()) && Block.byItem(event.getItemStack().getItem()) instanceof SilverfishBlock) {
LanguageHandler.sendPlayerMessage(event.getPlayer(), "Stop that you twat!!!");
event.setCanceled(true);
}
if (world.getBlockState(event.getPos()).getBlock().isBed(world.getBlockState(event.getPos()), world, event.getPos(), player)) {
final IColony colony = IColonyManager.getInstance().getColonyByPosFromWorld(world, bedBlockPos);
// Checks to see if player tries to sleep in a bed belonging to a Citizen, ancels the event, and Notifies Player that bed is occuppied
if (colony != null && world.getBlockState(event.getPos()).hasProperty(BedBlock.PART)) {
final List<ICitizenData> citizenList = colony.getCitizenManager().getCitizens();
final BlockState potentialBed = world.getBlockState(event.getPos());
if (potentialBed.getBlock() instanceof BedBlock && potentialBed.getValue(BedBlock.PART) == BedPart.FOOT) {
bedBlockPos = bedBlockPos.relative(world.getBlockState(event.getPos()).getValue(BedBlock.FACING));
}
for (final ICitizenData citizen : citizenList) {
if (citizen.getBedPos().equals(bedBlockPos) && citizen.isAsleep()) {
event.setCanceled(true);
LanguageHandler.sendPlayerMessage(player, "block.minecraft.bed.occupied");
}
}
}
}
handleEventCancellation(event, player);
if (!event.isCanceled() && event.getEntity() instanceof PlayerEntity && event.getItemStack().getItem() instanceof BlockItem) {
final Block block = ((BlockItem) event.getItemStack().getItem()).getBlock().getBlock();
if (block instanceof AbstractBlockHut && !(block instanceof IRSComponentBlock)) {
final IColony colony = IColonyManager.getInstance().getIColony(world, event.getPos());
if (colony != null && !colony.getPermissions().hasPermission(player, Action.ACCESS_HUTS)) {
event.setCanceled(true);
return;
}
if (MineColonies.getConfig().getServer().suggestBuildToolPlacement.get() && !(player.isCreative() && player.isShiftKeyDown())) {
final ItemStack stack = event.getItemStack();
if (!stack.isEmpty() && !world.isClientSide) {
Network.getNetwork().sendToPlayer(new OpenSuggestionWindowMessage(block.defaultBlockState().setValue(AbstractBlockHut.FACING, event.getPlayer().getDirection()), event.getPos().relative(event.getFace()), stack), (ServerPlayerEntity) player);
}
event.setCanceled(true);
}
return;
}
}
if (!event.isCanceled() && event.getItemStack().getItem() == ModItems.buildTool.get()) {
if (event.getWorld().isClientSide()) {
if (event.getUseBlock() == Event.Result.DEFAULT && event.getFace() != null) {
final IColonyView view = IColonyManager.getInstance().getClosestColonyView(event.getWorld(), event.getPos().relative(event.getFace()));
if (view != null && Settings.instance.getStyle().isEmpty()) {
Settings.instance.setStyle(view.getStyle());
}
MineColonies.proxy.openBuildToolWindow(event.getPos().relative(event.getFace()));
}
}
event.setCanceled(true);
}
if (!event.isCanceled() && event.getItemStack().getItem() == ModItems.shapeTool.get()) {
if (event.getWorld().isClientSide()) {
if (event.getUseBlock() == Event.Result.DEFAULT && event.getFace() != null) {
MineColonies.proxy.openShapeToolWindow(event.getPos().relative(event.getFace()));
}
}
event.setCanceled(true);
}
}
use of com.minecolonies.api.blocks.AbstractBlockHut in project minecolonies by ldtteam.
the class AbstractSchematicProvider method getRotation.
@Override
public int getRotation() {
if (cachedRotation != -1) {
return cachedRotation;
}
final StructureName structureName = new StructureName(Structures.SCHEMATICS_PREFIX, style, this.getSchematicName() + Math.max(1, buildingLevel));
try {
final LoadOnlyStructureHandler structure = new LoadOnlyStructureHandler(colony.getWorld(), getPosition(), structureName.toString(), new PlacementSettings(), true);
final Blueprint blueprint = structure.getBluePrint();
if (blueprint != null) {
final BlockState structureState = structure.getBluePrint().getBlockInfoAsMap().get(structure.getBluePrint().getPrimaryBlockOffset()).getState();
if (structureState != null) {
if (!(structureState.getBlock() instanceof AbstractBlockHut) || !(colony.getWorld().getBlockState(this.location).getBlock() instanceof AbstractBlockHut)) {
Log.getLogger().error(String.format("Schematic %s doesn't have a correct Primary Offset", structureName.toString()));
return 0;
}
final int structureRotation = structureState.getValue(AbstractBlockHut.FACING).get2DDataValue();
final int worldRotation = colony.getWorld().getBlockState(this.location).getValue(AbstractBlockHut.FACING).get2DDataValue();
if (structureRotation <= worldRotation) {
cachedRotation = worldRotation - structureRotation;
} else {
cachedRotation = 4 + worldRotation - structureRotation;
}
return cachedRotation;
}
}
} catch (Exception e) {
Log.getLogger().error(String.format("Failed to get rotation for %s: ", structureName.toString()), e);
return 0;
}
return 0;
}
Aggregations