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());
}
}
});
}
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);
}
}
Aggregations