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

Remove deprecated BlockRenderLayerMap#putItem* #4090

Merged
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -20,7 +20,6 @@
import net.minecraft.client.render.RenderLayer;
import net.minecraft.client.render.RenderLayers;
import net.minecraft.fluid.Fluid;
import net.minecraft.item.Item;

import net.fabricmc.fabric.impl.blockrenderlayer.BlockRenderLayerMapImpl;

Expand Down Expand Up @@ -56,20 +55,6 @@ public interface BlockRenderLayerMap {
*/
void putBlocks(RenderLayer renderLayer, Block... blocks);

/**
* @deprecated For blocks, calling {@link #putBlock(Block, RenderLayer)} is enough.
* Other items always use a translucent render layer.
*/
@Deprecated(forRemoval = true)
void putItem(Item item, RenderLayer renderLayer);

/**
* @deprecated For blocks, calling {@link #putBlocks(RenderLayer, Block...)} is enough.
* Other items always use a translucent render layer.
*/
@Deprecated(forRemoval = true)
void putItems(RenderLayer renderLayer, Item... items);

/**
* Map (or re-map) a fluid state with a render layer. Re-mapping is not recommended but if done, last one in wins.
* Must be called from client thread prior to world load/rendering. Best practice will be to call from mod's client initializer.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import net.minecraft.block.Block;
import net.minecraft.client.render.RenderLayer;
import net.minecraft.fluid.Fluid;
import net.minecraft.item.Item;

import net.fabricmc.fabric.api.blockrenderlayer.v1.BlockRenderLayerMap;

Expand All @@ -32,8 +31,8 @@ public BlockRenderLayerMapImpl() { }

@Override
public void putBlock(Block block, RenderLayer renderLayer) {
if (block == null) throw new IllegalArgumentException("Request to map null block to BlockRenderLayer");
if (renderLayer == null) throw new IllegalArgumentException("Request to map block " + block.toString() + " to null BlockRenderLayer");
if (block == null) throw new IllegalArgumentException("Request to map null block to RenderLayer");
if (renderLayer == null) throw new IllegalArgumentException("Request to map block " + block.toString() + " to null RenderLayer");

blockHandler.accept(block, renderLayer);
}
Expand All @@ -45,25 +44,10 @@ public void putBlocks(RenderLayer renderLayer, Block... blocks) {
}
}

@Override
public void putItem(Item item, RenderLayer renderLayer) {
if (item == null) throw new IllegalArgumentException("Request to map null item to BlockRenderLayer");
if (renderLayer == null) throw new IllegalArgumentException("Request to map item " + item.toString() + " to null BlockRenderLayer");

itemHandler.accept(item, renderLayer);
}

@Override
public void putItems(RenderLayer renderLayer, Item... items) {
for (Item item : items) {
putItem(item, renderLayer);
}
}

@Override
public void putFluid(Fluid fluid, RenderLayer renderLayer) {
if (fluid == null) throw new IllegalArgumentException("Request to map null fluid to BlockRenderLayer");
if (renderLayer == null) throw new IllegalArgumentException("Request to map fluid " + fluid.toString() + " to null BlockRenderLayer");
if (fluid == null) throw new IllegalArgumentException("Request to map null fluid to RenderLayer");
if (renderLayer == null) throw new IllegalArgumentException("Request to map fluid " + fluid.toString() + " to null RenderLayer");

fluidHandler.accept(fluid, renderLayer);
}
Expand All @@ -75,27 +59,20 @@ public void putFluids(RenderLayer renderLayer, Fluid... fluids) {
}
}

private static Map<Block, RenderLayer> blockRenderLayerMap = new HashMap<>();
private static Map<Item, RenderLayer> itemRenderLayerMap = new HashMap<>();
private static Map<Fluid, RenderLayer> fluidRenderLayerMap = new HashMap<>();
private static final Map<Block, RenderLayer> BLOCK_RENDER_LAYER_MAP = new HashMap<>();
private static final Map<Fluid, RenderLayer> FLUID_RENDER_LAYER_MAP = new HashMap<>();

//This consumers initially add to the maps above, and then are later set (when initialize is called) to insert straight into the target map.
private static BiConsumer<Block, RenderLayer> blockHandler = (b, l) -> blockRenderLayerMap.put(b, l);
private static BiConsumer<Item, RenderLayer> itemHandler = (i, l) -> itemRenderLayerMap.put(i, l);
private static BiConsumer<Fluid, RenderLayer> fluidHandler = (f, b) -> fluidRenderLayerMap.put(f, b);
// These consumers initially add to the maps above, and then are later set (when initialize is called) to insert straight into the target map.
private static BiConsumer<Block, RenderLayer> blockHandler = BLOCK_RENDER_LAYER_MAP::put;
private static BiConsumer<Fluid, RenderLayer> fluidHandler = FLUID_RENDER_LAYER_MAP::put;

public static void initialize(BiConsumer<Block, RenderLayer> blockHandlerIn, BiConsumer<Fluid, RenderLayer> fluidHandlerIn) {
//Done to handle backwards compat, in previous snapshots Items had their own map for render layers, now the BlockItem is used.
BiConsumer<Item, RenderLayer> itemHandlerIn = (item, renderLayer) -> blockHandlerIn.accept(Block.getBlockFromItem(item), renderLayer);

//Add all the pre existing render layers
blockRenderLayerMap.forEach(blockHandlerIn);
itemRenderLayerMap.forEach(itemHandlerIn);
fluidRenderLayerMap.forEach(fluidHandlerIn);
// Add all the preexisting render layers
BLOCK_RENDER_LAYER_MAP.forEach(blockHandlerIn);
FLUID_RENDER_LAYER_MAP.forEach(fluidHandlerIn);

//Set the handlers to directly accept later additions
// Set the handlers to directly accept later additions
blockHandler = blockHandlerIn;
itemHandler = itemHandlerIn;
fluidHandler = fluidHandlerIn;
}
}
Loading