Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e98fb29
commit a248516
Showing
10 changed files
with
158 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
src/main/java/knightminer/inspirations/tweaks/client/PortalColorHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package knightminer.inspirations.tweaks.client; | ||
|
||
import knightminer.inspirations.Inspirations; | ||
import knightminer.inspirations.library.Util; | ||
import net.minecraft.block.Block; | ||
import net.minecraft.block.BlockStainedGlass; | ||
import net.minecraft.block.BlockStainedGlassPane; | ||
import net.minecraft.block.state.IBlockState; | ||
import net.minecraft.client.renderer.color.IBlockColor; | ||
import net.minecraft.init.Blocks; | ||
import net.minecraft.util.math.BlockPos; | ||
import net.minecraft.world.ChunkCache; | ||
import net.minecraft.world.IBlockAccess; | ||
import net.minecraft.world.World; | ||
|
||
import javax.annotation.Nullable; | ||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
/** | ||
* Logic to handle getting the color for a portal from stained glass below | ||
*/ | ||
public class PortalColorHandler implements IBlockColor { | ||
private static final int DEFAULT_COLOR = 0x9928FF; | ||
private static final Set<Block> BEACON_COLOR_BLACKLIST = new HashSet<>(); | ||
|
||
@Override | ||
public int colorMultiplier(IBlockState state, @Nullable IBlockAccess world, @Nullable BlockPos pos, int tintIndex) { | ||
if (world == null || pos == null) { | ||
return DEFAULT_COLOR; | ||
} | ||
|
||
// iterate down until the first non-portal block | ||
// can skip every other block as it takes at least 2 from a portal to below a portal | ||
pos = pos.down(2); | ||
IBlockState colorState = world.getBlockState(pos); | ||
Block block = colorState.getBlock(); | ||
while(block == Blocks.PORTAL || block == Blocks.OBSIDIAN) { | ||
// update iterator | ||
pos = pos.down(block == Blocks.PORTAL ? 2 : 1); | ||
colorState = world.getBlockState(pos); | ||
block = colorState.getBlock(); | ||
} | ||
|
||
return getColorValue(world, pos); | ||
} | ||
|
||
/** | ||
* Gets the color for a block in the world, uses the same logic as beacon beam colors | ||
* @param access Block access | ||
* @param pos Block pos | ||
* @return | ||
*/ | ||
private static int getColorValue(IBlockAccess access, BlockPos pos) { | ||
IBlockState state = access.getBlockState(pos); | ||
Block block = state.getBlock(); | ||
// stained glass | ||
if (block == Blocks.STAINED_GLASS) { | ||
return state.getValue(BlockStainedGlass.COLOR).colorValue; | ||
} | ||
if (block == Blocks.STAINED_GLASS_PANE) { | ||
return state.getValue(BlockStainedGlassPane.COLOR).colorValue; | ||
} | ||
// beacon color fallback | ||
if (!BEACON_COLOR_BLACKLIST.contains(block)) { | ||
World world = null; | ||
if (access instanceof World) { | ||
world = (World)access; | ||
} else if (access instanceof ChunkCache) { | ||
world = ((ChunkCache)access).world; | ||
} | ||
if (world != null) { | ||
try { | ||
float[] color = block.getBeaconColorMultiplier(state, world, pos, pos); | ||
if (color != null && color.length == 3) { | ||
return Util.getColorInteger(color); | ||
} | ||
} catch (ClassCastException e) { | ||
Inspirations.log.error("Error getting beacon color for block", e); | ||
BEACON_COLOR_BLACKLIST.add(block); | ||
} | ||
} | ||
} | ||
|
||
return DEFAULT_COLOR; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
src/main/resources/assets/inspirations/blockstates/portal.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"variants": { | ||
"axis=z": { "model": "inspirations:portal_ew" }, | ||
"axis=x": { "model": "inspirations:portal_ns" } | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/resources/assets/inspirations/models/block/portal_ew.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"textures": { | ||
"particle": "blocks/portal", | ||
"portal": "inspirations:blocks/portal" | ||
}, | ||
"elements": [ | ||
{ "from": [ 6, 0, 0 ], | ||
"to": [ 10, 16, 16 ], | ||
"faces": { | ||
"east": { "uv": [ 0, 0, 16, 16 ], "texture": "#portal", "tintindex": 0 }, | ||
"west": { "uv": [ 0, 0, 16, 16 ], "texture": "#portal", "tintindex": 0 } | ||
} | ||
} | ||
] | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/resources/assets/inspirations/models/block/portal_ns.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"textures": { | ||
"particle": "blocks/portal", | ||
"portal": "inspirations:blocks/portal" | ||
}, | ||
"elements": [ | ||
{ "from": [ 0, 0, 6 ], | ||
"to": [ 16, 16, 10 ], | ||
"faces": { | ||
"north": { "uv": [ 0, 0, 16, 16 ], "texture": "#portal", "tintindex": 0 }, | ||
"south": { "uv": [ 0, 0, 16, 16 ], "texture": "#portal", "tintindex": 0 } | ||
} | ||
} | ||
] | ||
} |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
src/main/resources/assets/inspirations/textures/blocks/portal.png.mcmeta
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"animation": {} | ||
} |