Skip to content

Commit

Permalink
priority text translation and zone block only creative placable.
Browse files Browse the repository at this point in the history
  • Loading branch information
rotgruengelb committed Jan 27, 2024
1 parent aa2d973 commit d736e3c
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
@Environment(EnvType.CLIENT)
public class LandscapeClient implements ClientModInitializer {

public static final Logger CLOGGER = LoggerFactory.getLogger("Landscape/CLIENT");
public static final Logger C_LOGGER = LoggerFactory.getLogger("Landscape/CLIENT");

@Override
public void onInitializeClient() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
public class ZoneBlockScreen extends Screen {
private static final ImmutableList<ZoneBlockMode> MODES = ImmutableList.copyOf(ZoneBlockMode.values());
private static final Text SHOW_ZONES_TEXT = Text.translatable("text.landscape.zone_block.screen.show_zones");
private static final Text SET_PRIORITY_TEXT = Text.translatable("text.landscape.zone_block.screen.set_priority");
private static final Text title = Text.translatable("text.landscape.zone_block.screen.title");
private final BlockPos pos;
private final ZoneBlockMode originalMode;
Expand Down Expand Up @@ -192,7 +193,7 @@ public void render(DrawContext context, int mouseX, int mouseY, float delta) {
super.render(context, mouseX, mouseY, delta);
this.inputZones.render(context, mouseX, mouseY, delta);
this.inputPriority.render(context, mouseX, mouseY, delta);
context.drawTextWithShadow(this.textRenderer, Text.literal("Priority"), this.width / 2 - 153, 70, 0xA0A0A0);
context.drawTextWithShadow(this.textRenderer, SET_PRIORITY_TEXT, this.width / 2 - 153, 70, 0xA0A0A0);
context.drawTextWithShadow(this.textRenderer, SHOW_ZONES_TEXT, this.width / 2 + 154 - this.textRenderer.getWidth(SHOW_ZONES_TEXT), 70, 0xA0A0A0);
context.drawCenteredTextWithShadow(this.textRenderer, title, this.width / 2, 10, 0xFFFFFF);
context.drawTextWithShadow(this.textRenderer, this.newMode.asText(), this.width / 2 - 153, 174, 0xA0A0A0);
Expand Down
9 changes: 6 additions & 3 deletions src/main/java/net/rotgruengelb/landscape/block/ModBlocks.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,19 @@
import net.minecraft.block.Block;
import net.minecraft.block.Blocks;
import net.minecraft.item.BlockItem;
import net.minecraft.item.Item;
import net.minecraft.item.ItemGroups;
import net.minecraft.item.Items;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
import net.minecraft.util.Identifier;
import net.rotgruengelb.landscape.Landscape;
import net.rotgruengelb.landscape.item.ZoneBlockItem;

public class ModBlocks {

public static final Block ZONE_BLOCK = registerBlock("zone_block", new ZoneBlock(FabricBlockSettings.copyOf(Blocks.STRUCTURE_BLOCK)));
public static final Block ZONE_BLOCK = registerBlockNoItem("zone_block", new ZoneBlock(FabricBlockSettings.copyOf(Blocks.STRUCTURE_BLOCK)));
public static final Item ZONE_BLOCK_ITEM = registerBlockItem("zone_block", new ZoneBlockItem(ZONE_BLOCK, new FabricItemSettings()));

private static Block registerBlockNoItem(String name, Block block) {
return Registry.register(Registries.BLOCK, new Identifier(Landscape.MOD_ID, name), block);
Expand All @@ -26,8 +29,8 @@ private static Block registerBlock(String name, Block block) {
return Registry.register(Registries.BLOCK, new Identifier(Landscape.MOD_ID, name), block);
}

private static void registerBlockItem(String name, BlockItem blockItem) {
Registry.register(Registries.ITEM, new Identifier(Landscape.MOD_ID, name), blockItem);
private static BlockItem registerBlockItem(String name, BlockItem blockItem) {
return Registry.register(Registries.ITEM, new Identifier(Landscape.MOD_ID, name), blockItem);
}

public static void registerModBlocks() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.world.World;
import net.minecraft.world.WorldView;
import net.rotgruengelb.landscape.block.entity.ZoneBlockBlockEntity;
import net.rotgruengelb.landscape.block.enums.ZoneBlockMode;
import net.rotgruengelb.landscape.state.ModProperties;
Expand All @@ -42,8 +43,11 @@ public BlockEntity createBlockEntity(BlockPos pos, BlockState state) {

@Override
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
if (!player.isCreativeLevelTwoOp()) {
return ActionResult.PASS;
}
BlockEntity blockEntity = world.getBlockEntity(pos);
if (blockEntity instanceof ZoneBlockBlockEntity && player.isCreativeLevelTwoOp()) {
if (blockEntity instanceof ZoneBlockBlockEntity) {
return ((ZoneBlockBlockEntity) blockEntity).openScreen(player) ? ActionResult.success(world.isClient) : ActionResult.PASS;
}
return ActionResult.PASS;
Expand Down
22 changes: 22 additions & 0 deletions src/main/java/net/rotgruengelb/landscape/item/ZoneBlockItem.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package net.rotgruengelb.landscape.item;

import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.item.BlockItem;
import net.minecraft.item.ItemPlacementContext;
import net.rotgruengelb.landscape.Landscape;

public class ZoneBlockItem extends BlockItem {
public ZoneBlockItem(Block block, Settings settings) {
super(block, settings);
}

@Override
protected boolean canPlace(ItemPlacementContext context, BlockState state) {
if (context.getPlayer().isCreativeLevelTwoOp()) {
return super.canPlace(context, state);
} else {
return false;
}
}
}
1 change: 1 addition & 0 deletions src/main/resources/assets/landscape/lang/en_us.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"block.landscape.zone_block": "Zone Block",
"text.landscape.zone_block.screen.show_zones": "Show zones:",
"text.landscape.zone_block.screen.set_priority": "Priority",
"text.landscape.zone_block.screen.title": "Zone Block",
"text.landscape.zone_block.mode_info.trigger": "Trigger Mode - Execute on Player entry",
"text.landscape.zone_block.mode_info.deny_break": "Deny Break Mode - Deny Block breaking",
Expand Down

0 comments on commit d736e3c

Please sign in to comment.