Search in sources :

Example 1 with EnumType

use of com.codetaylor.mc.artisanworktables.api.internal.reference.EnumType in project artisan-worktables by codetaylor.

the class BlockModelRegistrationStrategy method register.

@Override
public void register() {
    BlockBase.VARIANT.getAllowedValues().forEach(type -> {
        IBlockState state = this.block.getDefaultState().withProperty(BlockBase.VARIANT, type);
        Block block = state.getBlock();
        Item item = Item.getItemFromBlock(block);
        ModelLoader.setCustomModelResourceLocation(item, type.getMeta(), new ModelResourceLocation(Preconditions.checkNotNull(item.getRegistryName(), "Item %s has null registry name", item), BlockBase.VARIANT.getName() + "=" + type.getName()));
    });
    IBlockState state = this.block.getDefaultState().withProperty(BlockBase.VARIANT, EnumType.MAGE);
    Block block = state.getBlock();
    Item item = Item.getItemFromBlock(block);
    ModelLoader.setCustomModelResourceLocation(item, Short.MAX_VALUE / 2 + EnumType.MAGE.getMeta(), new ModelResourceLocation(Preconditions.checkNotNull(item.getRegistryName(), "Item %s has null registry name", item), BlockBase.VARIANT.getName() + "=" + EnumType.MAGE.getName() + "_active"));
    ModelLoader.setCustomStateMapper(this.block, new DefaultStateMapper() {

        @Nonnull
        @Override
        protected ModelResourceLocation getModelResourceLocation(IBlockState state) {
            EnumType type = state.getValue(BlockBase.VARIANT);
            if (type == EnumType.MAGE) {
                Block block = state.getBlock();
                boolean active = state.getValue(BlockBase.ACTIVE);
                return new ModelResourceLocation(Preconditions.checkNotNull(Block.REGISTRY.getNameForObject(block), "Block %s has null registry name", block), BlockBase.VARIANT.getName() + "=" + type.getName() + (active ? "_active" : ""));
            } else {
                Block block = state.getBlock();
                return new ModelResourceLocation(Preconditions.checkNotNull(Block.REGISTRY.getNameForObject(block), "Block %s has null registry name", block), BlockBase.VARIANT.getName() + "=" + type.getName());
            }
        }
    });
}
Also used : Item(net.minecraft.item.Item) IBlockState(net.minecraft.block.state.IBlockState) DefaultStateMapper(net.minecraft.client.renderer.block.statemap.DefaultStateMapper) Nonnull(javax.annotation.Nonnull) EnumType(com.codetaylor.mc.artisanworktables.api.internal.reference.EnumType) Block(net.minecraft.block.Block) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation)

Example 2 with EnumType

use of com.codetaylor.mc.artisanworktables.api.internal.reference.EnumType in project artisan-worktables by codetaylor.

the class TileEntityBase method initialize.

protected void initialize(EnumType type) {
    this.uuid = type.getName() + "." + this.getTier().getName();
    this.craftingMatrixHandler = this.createCraftingMatrixHandler();
    this.toolHandler = this.createToolHandler();
    this.secondaryOutputHandler = this.createSecondaryOutputHandler();
    this.resultHandler = new ItemStackHandler(1);
    this.tank = this.createFluidTank(type);
    {
        ObservableStackHandler.IContentsChangedEventHandler contentsChangedEventHandler;
        contentsChangedEventHandler = (stackHandler, slotIndex) -> {
            this.markDirty();
            this.requiresRecipeUpdate = true;
            if (this.isLocked()) {
                ItemStack stackInSlot = stackHandler.getStackInSlot(slotIndex);
                if (!stackInSlot.isEmpty()) {
                    ItemStack copy = stackInSlot.copy();
                    copy.setCount(1);
                    this.craftingMatrixHandlerGhost.setStackInSlot(slotIndex, copy);
                }
            }
            this.notifyBlockUpdate();
        };
        this.craftingMatrixHandler.addObserver(contentsChangedEventHandler);
        this.toolHandler.addObserver(contentsChangedEventHandler);
        this.secondaryOutputHandler.addObserver(contentsChangedEventHandler);
    }
    this.craftingMatrixHandlerGhost = new CraftingMatrixStackHandler(this.craftingMatrixHandler.getWidth(), this.craftingMatrixHandler.getHeight());
    this.roundRobinGhostStackHandler = new RoundRobinGhostStackHandler(this, this.craftingMatrixHandler, this.craftingMatrixHandlerGhost);
    {
        ObservableStackHandler.IContentsChangedEventHandler contentsChangedEventHandler;
        contentsChangedEventHandler = (stackHandler, slotIndex) -> {
            this.markDirty();
        };
        this.craftingMatrixHandlerGhost.addObserver(contentsChangedEventHandler);
    }
}
Also used : IItemHandler(net.minecraftforge.items.IItemHandler) SPacketUpdateTileEntity(net.minecraft.network.play.server.SPacketUpdateTileEntity) Item(net.minecraft.item.Item) EnchantmentHelper(com.codetaylor.mc.athenaeum.util.EnchantmentHelper) ICraftingMatrixStackHandler(com.codetaylor.mc.artisanworktables.api.internal.recipe.ICraftingMatrixStackHandler) IArtisanRecipe(com.codetaylor.mc.artisanworktables.api.recipe.IArtisanRecipe) ModuleWorktablesConfig(com.codetaylor.mc.artisanworktables.modules.worktables.ModuleWorktablesConfig) AWGuiContainerBase(com.codetaylor.mc.artisanworktables.modules.worktables.gui.AWGuiContainerBase) Block(net.minecraft.block.Block) IntHashMap(net.minecraft.util.IntHashMap) EnumType(com.codetaylor.mc.artisanworktables.api.internal.reference.EnumType) ObservableStackHandler(com.codetaylor.mc.athenaeum.inventory.ObservableStackHandler) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) Predicate(java.util.function.Predicate) ArtisanRegistries(com.codetaylor.mc.artisanworktables.api.ArtisanRegistries) VanillaRecipeCache(com.codetaylor.mc.artisanworktables.modules.worktables.recipe.VanillaRecipeCache) IForgeRegistry(net.minecraftforge.registries.IForgeRegistry) Capability(net.minecraftforge.common.capabilities.Capability) RecipeRegistry(com.codetaylor.mc.artisanworktables.api.internal.recipe.RecipeRegistry) ItemStackHandler(net.minecraftforge.items.ItemStackHandler) BlockHelper(com.codetaylor.mc.athenaeum.util.BlockHelper) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ISecondaryIngredientMatcher(com.codetaylor.mc.artisanworktables.api.internal.recipe.ISecondaryIngredientMatcher) CapabilityItemHandler(net.minecraftforge.items.CapabilityItemHandler) FluidStack(net.minecraftforge.fluids.FluidStack) FluidTank(net.minecraftforge.fluids.FluidTank) SCPacketWorktableFluidUpdate(com.codetaylor.mc.artisanworktables.modules.worktables.network.SCPacketWorktableFluidUpdate) EnumTier(com.codetaylor.mc.artisanworktables.api.internal.reference.EnumTier) java.util(java.util) IRequirementContext(com.codetaylor.mc.artisanworktables.api.recipe.requirement.IRequirementContext) TileEntityToolbox(com.codetaylor.mc.artisanworktables.modules.toolbox.tile.TileEntityToolbox) NetworkManager(net.minecraft.network.NetworkManager) IContainerProvider(com.codetaylor.mc.athenaeum.tile.IContainerProvider) ItemStack(net.minecraft.item.ItemStack) ModuleWorktables(com.codetaylor.mc.artisanworktables.modules.worktables.ModuleWorktables) ITickable(net.minecraft.util.ITickable) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) RoundRobinGhostStackHandler(com.codetaylor.mc.artisanworktables.modules.worktables.tile.RoundRobinGhostStackHandler) IContainer(com.codetaylor.mc.athenaeum.tile.IContainer) CapabilityFluidHandler(net.minecraftforge.fluids.capability.CapabilityFluidHandler) World(net.minecraft.world.World) RequirementContextSupplier(com.codetaylor.mc.artisanworktables.api.recipe.requirement.RequirementContextSupplier) ArtisanAPI(com.codetaylor.mc.artisanworktables.api.ArtisanAPI) EnumFacing(net.minecraft.util.EnumFacing) BlockPos(net.minecraft.util.math.BlockPos) InventoryPlayer(net.minecraft.entity.player.InventoryPlayer) IBlockState(net.minecraft.block.state.IBlockState) AWContainer(com.codetaylor.mc.artisanworktables.modules.worktables.gui.AWContainer) ResourceLocation(net.minecraft.util.ResourceLocation) TileEntity(net.minecraft.tileentity.TileEntity) ModArtisanWorktables(com.codetaylor.mc.artisanworktables.ModArtisanWorktables) CraftingContextFactory(com.codetaylor.mc.artisanworktables.modules.worktables.recipe.CraftingContextFactory) ICraftingContext(com.codetaylor.mc.artisanworktables.api.internal.recipe.ICraftingContext) ItemStackHandler(net.minecraftforge.items.ItemStackHandler) RoundRobinGhostStackHandler(com.codetaylor.mc.artisanworktables.modules.worktables.tile.RoundRobinGhostStackHandler) ICraftingMatrixStackHandler(com.codetaylor.mc.artisanworktables.api.internal.recipe.ICraftingMatrixStackHandler) ItemStack(net.minecraft.item.ItemStack)

Aggregations

EnumType (com.codetaylor.mc.artisanworktables.api.internal.reference.EnumType)2 Nonnull (javax.annotation.Nonnull)2 Block (net.minecraft.block.Block)2 IBlockState (net.minecraft.block.state.IBlockState)2 Item (net.minecraft.item.Item)2 ModArtisanWorktables (com.codetaylor.mc.artisanworktables.ModArtisanWorktables)1 ArtisanAPI (com.codetaylor.mc.artisanworktables.api.ArtisanAPI)1 ArtisanRegistries (com.codetaylor.mc.artisanworktables.api.ArtisanRegistries)1 ICraftingContext (com.codetaylor.mc.artisanworktables.api.internal.recipe.ICraftingContext)1 ICraftingMatrixStackHandler (com.codetaylor.mc.artisanworktables.api.internal.recipe.ICraftingMatrixStackHandler)1 ISecondaryIngredientMatcher (com.codetaylor.mc.artisanworktables.api.internal.recipe.ISecondaryIngredientMatcher)1 RecipeRegistry (com.codetaylor.mc.artisanworktables.api.internal.recipe.RecipeRegistry)1 EnumTier (com.codetaylor.mc.artisanworktables.api.internal.reference.EnumTier)1 IArtisanRecipe (com.codetaylor.mc.artisanworktables.api.recipe.IArtisanRecipe)1 IRequirementContext (com.codetaylor.mc.artisanworktables.api.recipe.requirement.IRequirementContext)1 RequirementContextSupplier (com.codetaylor.mc.artisanworktables.api.recipe.requirement.RequirementContextSupplier)1 TileEntityToolbox (com.codetaylor.mc.artisanworktables.modules.toolbox.tile.TileEntityToolbox)1 ModuleWorktables (com.codetaylor.mc.artisanworktables.modules.worktables.ModuleWorktables)1 ModuleWorktablesConfig (com.codetaylor.mc.artisanworktables.modules.worktables.ModuleWorktablesConfig)1 AWContainer (com.codetaylor.mc.artisanworktables.modules.worktables.gui.AWContainer)1