Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify item block registry #10170

Open
wants to merge 7 commits into
base: version/1.21
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import net.minecraft.world.level.block.state.properties.EnumProperty;
import org.jetbrains.annotations.NotNull;

public abstract class AbstractBlockBarrel<B extends AbstractBlockBarrel<B>> extends AbstractBlockMinecoloniesHorizontal<B> implements ITickableBlockMinecolonies
public abstract class AbstractBlockBarrel<B extends AbstractBlockBarrel<B>> extends HorizontalDirectionalBlock implements ITickableBlockMinecolonies
{
public static final EnumProperty<BarrelType> VARIANT = EnumProperty.create("variant", BarrelType.class);

Expand Down
52 changes: 6 additions & 46 deletions src/main/java/com/minecolonies/api/blocks/AbstractBlockHut.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,27 @@
import com.minecolonies.api.colony.buildings.views.IBuildingView;
import com.minecolonies.api.colony.permissions.Action;
import com.minecolonies.api.entity.ai.workers.util.IBuilderUndestroyable;
import com.minecolonies.api.items.ItemBlockHut;
import com.minecolonies.api.tileentities.AbstractTileEntityColonyBuilding;
import com.minecolonies.api.tileentities.MinecoloniesTileEntities;
import com.minecolonies.core.tileentities.TileEntityColonyBuilding;
import com.minecolonies.api.util.*;
import com.minecolonies.api.util.constant.Constants;
import com.minecolonies.api.util.constant.TranslationConstants;
import net.minecraft.ChatFormatting;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.Registry;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.network.chat.Style;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.ItemInteractionResult;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.context.BlockPlaceContext;
import net.minecraft.world.level.BlockGetter;
Expand Down Expand Up @@ -79,7 +75,7 @@
* All AbstractBlockHut[something] should extend this class.
*/
@SuppressWarnings("PMD.ExcessiveImports")
public abstract class AbstractBlockHut<B extends AbstractBlockHut<B>> extends AbstractBlockMinecolonies<B> implements IBuilderUndestroyable,
public abstract class AbstractBlockHut<B extends AbstractBlockHut<B>> extends Block implements IBuilderUndestroyable,
IAnchorBlock,
ITickableBlockMinecolonies,
INamedBlueprintAnchorBlock,
Expand Down Expand Up @@ -115,11 +111,6 @@ public abstract class AbstractBlockHut<B extends AbstractBlockHut<B>> extends Ab
*/
private static final VoxelShape SHAPE = Shapes.box(0.1, 0.1, 0.1, 0.9, 0.9, 0.9);

/**
* The hut's lower-case building-registry-compatible name.
*/
private final String name;

/**
* The timepoint of the last chat warning message
*/
Expand All @@ -134,7 +125,6 @@ public AbstractBlockHut()
{
super(Properties.of().mapColor(MapColor.WOOD).sound(SoundType.WOOD).strength(HARDNESS, RESISTANCE).noOcclusion());
this.registerDefaultState(this.defaultBlockState().setValue(FACING, Direction.NORTH));
this.name = getHutName();
}

@Override
Expand All @@ -161,16 +151,8 @@ public AbstractBlockHut(final Properties properties)
{
super(properties.noOcclusion());
this.registerDefaultState(this.defaultBlockState().setValue(FACING, Direction.NORTH));
this.name = getHutName();
}

/**
* Method to return the name of the block.
*
* @return Name of the block.
*/
public abstract String getHutName();

@Nullable
@Override
public BlockEntity newBlockEntity(@NotNull final BlockPos blockPos, @NotNull final BlockState blockState)
Expand Down Expand Up @@ -341,22 +323,6 @@ public void onBlockPlacedByBuildTool(
setPlacedBy(worldIn, pos, state, placer, stack);
}

/**
* Get the registry name frm the blck hut.
* @return the key.
*/
public ResourceLocation getRegistryName()
{
return new ResourceLocation(Constants.MOD_ID, getHutName());
}

@Override
public B registerBlock(final Registry<Block> registry)
{
Registry.register(registry, getRegistryName(), this);
return (B) this;
}

@Override
public boolean isVisible(@Nullable final CompoundTag beData)
{
Expand All @@ -378,7 +344,7 @@ public List<MutableComponent> getRequirements(final ClientLevel level, final Blo

if (InventoryUtils.findFirstSlotInItemHandlerWith(new InvWrapper(player.getInventory()), this) == -1)
{
requirements.add(Component.translatableEscape("com.minecolonies.coremod.hut.cost", Component.translatableEscape("block." + Constants.MOD_ID + "." + getHutName())).setStyle((Style.EMPTY).withColor(ChatFormatting.RED)));
requirements.add(Component.translatableEscape("com.minecolonies.coremod.hut.cost", Component.translatableEscape(getDescriptionId())).setStyle((Style.EMPTY).withColor(ChatFormatting.RED)));
return requirements;
}

Expand Down Expand Up @@ -437,7 +403,7 @@ public int getLevel(final CompoundTag beData)
}
catch (final NumberFormatException exception)
{
Log.getLogger().error("Couldn't get level from hut: " + getHutName() + ". Potential corrubt blockEntity data.");
Log.getLogger().error("Couldn't get level from hut: " + BuiltInRegistries.BLOCK.getKey(this) + ". Potential corrubt blockEntity data.");
return 0;
}
}
Expand Down Expand Up @@ -488,7 +454,7 @@ public boolean setup(
@Nullable final IBuilding building = IColonyManager.getInstance().getBuilding(world, pos);
if (building == null)
{
if (anchor.getBlock() != ModBlocks.blockHutTownHall)
if (anchor.getBlock() != ModBlocks.blockHutTownHall.get())
{
SoundUtils.playErrorSound(player, player.blockPosition());
Log.getLogger().error("BuildTool: building is null!", new Exception());
Expand Down Expand Up @@ -545,7 +511,7 @@ private boolean canPaste(final Block anchor, final Player player, final BlockPos

if (colony == null)
{
if(anchor == ModBlocks.blockHutTownHall)
if(anchor == ModBlocks.blockHutTownHall.get())
{
return true;
}
Expand Down Expand Up @@ -582,10 +548,4 @@ public String getBlueprintName()
{
return getBuildingEntry().getRegistryName().getPath();
}

@Override
public void registerBlockItem(final Registry<Item> registry, final Item.Properties properties)
{
Registry.register(registry, getRegistryName(), new ItemBlockHut(this, properties));
}
}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package com.minecolonies.api.blocks;

import com.minecolonies.api.blocks.types.GraveType;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.EntityBlock;
import net.minecraft.world.level.block.HorizontalDirectionalBlock;
import net.minecraft.world.level.block.state.properties.DirectionProperty;
import net.minecraft.world.level.block.state.properties.EnumProperty;

public abstract class AbstractBlockMinecoloniesGrave<B extends AbstractBlockMinecoloniesGrave<B>> extends AbstractBlockMinecolonies<B> implements EntityBlock
public abstract class AbstractBlockMinecoloniesGrave<B extends AbstractBlockMinecoloniesGrave<B>> extends Block implements EntityBlock
{
public static final EnumProperty<GraveType> VARIANT = EnumProperty.create("variant", GraveType.class);

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package com.minecolonies.api.blocks;

import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.EntityBlock;
import net.minecraft.world.level.block.HorizontalDirectionalBlock;
import net.minecraft.world.level.block.state.properties.DirectionProperty;

/**
* Abstract class for minecolonies named graves.
*/
public abstract class AbstractBlockMinecoloniesNamedGrave<B extends AbstractBlockMinecoloniesNamedGrave<B>> extends AbstractBlockMinecolonies<B> implements EntityBlock
public abstract class AbstractBlockMinecoloniesNamedGrave<B extends AbstractBlockMinecoloniesNamedGrave<B>> extends Block implements EntityBlock
{
/**
* The direction the block is facing.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import net.minecraft.world.level.block.state.properties.DirectionProperty;
import net.minecraft.world.level.block.state.properties.EnumProperty;

public abstract class AbstractBlockMinecoloniesRack<B extends AbstractBlockMinecoloniesRack<B>> extends AbstractBlockMinecolonies<B> implements EntityBlock
public abstract class AbstractBlockMinecoloniesRack<B extends AbstractBlockMinecoloniesRack<B>> extends Block implements EntityBlock
{
public static final EnumProperty<RackType> VARIANT = EnumProperty.create("variant", RackType.class);

Expand Down
Loading