Aurora crystal

This commit is contained in:
paulevsGitch 2020-10-07 08:57:22 +03:00
parent 6ab57f3e4b
commit cc05c21f62
10 changed files with 154 additions and 0 deletions

View file

@ -0,0 +1,76 @@
package ru.betterend.blocks;
import java.util.Collections;
import java.util.List;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags;
import net.minecraft.block.AbstractGlassBlock;
import net.minecraft.block.BlockState;
import net.minecraft.block.Material;
import net.minecraft.client.color.block.BlockColorProvider;
import net.minecraft.client.color.item.ItemColorProvider;
import net.minecraft.item.ItemStack;
import net.minecraft.loot.context.LootContext;
import net.minecraft.sound.BlockSoundGroup;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Vec3i;
import ru.betterend.client.ERenderLayer;
import ru.betterend.client.IRenderTypeable;
import ru.betterend.util.IColorProvider;
import ru.betterend.util.MHelper;
public class AuroraCrystalBlock extends AbstractGlassBlock implements IRenderTypeable, IColorProvider {
private static final Vec3i[] COLORS;
public AuroraCrystalBlock() {
super(FabricBlockSettings.of(Material.GLASS).breakByTool(FabricToolTags.PICKAXES).sounds(BlockSoundGroup.GLASS).lightLevel(15).nonOpaque());
}
@Override
public BlockColorProvider getProvider() {
return (state, world, pos, tintIndex) -> {
long i = (long) pos.getX() + (long) pos.getY() + (long) pos.getZ();
double delta = i * 0.1;
int index = MHelper.floor(delta);
int index2 = (index + 1) & 3;
delta -= index;
index &= 3;
Vec3i color1 = COLORS[index];
Vec3i color2 = COLORS[index2];
int r = MHelper.floor(MathHelper.lerp(delta, color1.getX(), color2.getX()));
int g = MHelper.floor(MathHelper.lerp(delta, color1.getY(), color2.getY()));
int b = MHelper.floor(MathHelper.lerp(delta, color1.getZ(), color2.getZ()));
return MHelper.color(r, g, b);
};
}
@Override
public ItemColorProvider getItemProvider() {
return (stack, tintIndex) -> {
return MHelper.color(COLORS[3].getX(), COLORS[3].getY(), COLORS[3].getZ());
};
}
@Override
public ERenderLayer getRenderLayer() {
return ERenderLayer.TRANSLUCENT;
}
@Override
public List<ItemStack> getDroppedStacks(BlockState state, LootContext.Builder builder) {
return Collections.singletonList(new ItemStack(this));
}
static {
COLORS = new Vec3i[] {
new Vec3i(247, 77, 161),
new Vec3i(120, 184, 255),
new Vec3i(120, 255, 168),
new Vec3i(243, 58, 255)
};
}
}

View file

@ -2,12 +2,15 @@ package ru.betterend.client;
import net.fabricmc.api.ClientModInitializer; import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.blockrenderlayer.v1.BlockRenderLayerMap; import net.fabricmc.fabric.api.blockrenderlayer.v1.BlockRenderLayerMap;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.color.block.BlockColors;
import net.minecraft.client.render.RenderLayer; import net.minecraft.client.render.RenderLayer;
import net.minecraft.util.registry.Registry; import net.minecraft.util.registry.Registry;
import ru.betterend.registry.BlockEntityRenderRegistry; import ru.betterend.registry.BlockEntityRenderRegistry;
import ru.betterend.registry.EntityRenderRegistry; import ru.betterend.registry.EntityRenderRegistry;
import ru.betterend.registry.ParticleRegistry; import ru.betterend.registry.ParticleRegistry;
import ru.betterend.registry.ScreensRegistry; import ru.betterend.registry.ScreensRegistry;
import ru.betterend.util.IColorProvider;
public class BetterEndClient implements ClientModInitializer { public class BetterEndClient implements ClientModInitializer {
@Override @Override

View file

@ -5,9 +5,14 @@ import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import net.fabricmc.fabric.api.blockrenderlayer.v1.BlockRenderLayerMap;
import net.minecraft.client.MinecraftClient; import net.minecraft.client.MinecraftClient;
import net.minecraft.client.RunArgs;
import net.minecraft.client.color.block.BlockColors;
import net.minecraft.client.color.item.ItemColors;
import net.minecraft.client.gui.hud.InGameHud; import net.minecraft.client.gui.hud.InGameHud;
import net.minecraft.client.gui.screen.CreditsScreen; import net.minecraft.client.gui.screen.CreditsScreen;
import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.gui.screen.Screen;
@ -15,7 +20,11 @@ import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.client.sound.MusicType; import net.minecraft.client.sound.MusicType;
import net.minecraft.client.world.ClientWorld; import net.minecraft.client.world.ClientWorld;
import net.minecraft.sound.MusicSound; import net.minecraft.sound.MusicSound;
import net.minecraft.util.registry.Registry;
import net.minecraft.world.World; import net.minecraft.world.World;
import ru.betterend.client.ERenderLayer;
import ru.betterend.client.IRenderTypeable;
import ru.betterend.util.IColorProvider;
import ru.betterend.util.MHelper; import ru.betterend.util.MHelper;
@Mixin(MinecraftClient.class) @Mixin(MinecraftClient.class)
@ -33,6 +42,25 @@ public class MinecraftClientMixin {
@Shadow @Shadow
public ClientWorld world; public ClientWorld world;
@Shadow
@Final
private BlockColors blockColors;
@Shadow
@Final
private ItemColors itemColors;
@Inject(method = "<init>*", at = @At("TAIL"))
private void onInit(RunArgs args, CallbackInfo info) {
Registry.BLOCK.forEach(block -> {
if (block instanceof IColorProvider) {
IColorProvider provider = (IColorProvider) block;
blockColors.registerColorProvider(provider.getProvider(), block);
itemColors.register(provider.getItemProvider(), block.asItem());
}
});
}
@Inject(method = "getMusicType", at = @At("HEAD"), cancellable = true) @Inject(method = "getMusicType", at = @At("HEAD"), cancellable = true)
private void getEndMusic(CallbackInfoReturnable<MusicSound> info) { private void getEndMusic(CallbackInfoReturnable<MusicSound> info) {
if (!(this.currentScreen instanceof CreditsScreen) && this.player != null) { if (!(this.currentScreen instanceof CreditsScreen) && this.player != null) {

View file

@ -7,6 +7,7 @@ import net.minecraft.item.Item;
import net.minecraft.util.registry.Registry; import net.minecraft.util.registry.Registry;
import ru.betterend.BetterEnd; import ru.betterend.BetterEnd;
import ru.betterend.blocks.AeterniumBlock; import ru.betterend.blocks.AeterniumBlock;
import ru.betterend.blocks.AuroraCrystalBlock;
import ru.betterend.blocks.BlockBlueVine; import ru.betterend.blocks.BlockBlueVine;
import ru.betterend.blocks.BlockBlueVineLantern; import ru.betterend.blocks.BlockBlueVineLantern;
import ru.betterend.blocks.BlockBlueVineSeed; import ru.betterend.blocks.BlockBlueVineSeed;
@ -65,6 +66,7 @@ public class BlockRegistry {
public static final Block TERMINITE_BLOCK = registerBlock("terminite_block", new TerminiteBlock()); public static final Block TERMINITE_BLOCK = registerBlock("terminite_block", new TerminiteBlock());
public static final Block AETERNIUM_BLOCK = registerBlock("aeternium_block", new AeterniumBlock()); public static final Block AETERNIUM_BLOCK = registerBlock("aeternium_block", new AeterniumBlock());
public static final Block ENDER_BLOCK = registerBlock("ender_block", new EnderBlock()); public static final Block ENDER_BLOCK = registerBlock("ender_block", new EnderBlock());
public static final Block AURORA_CRYSTAL = registerBlock("aurora_crystal", new AuroraCrystalBlock());
// Block With Entities // // Block With Entities //
public static final Block END_STONE_SMELTER = registerBlock("end_stone_smelter", new EndStoneSmelter()); public static final Block END_STONE_SMELTER = registerBlock("end_stone_smelter", new EndStoneSmelter());

View file

@ -0,0 +1,10 @@
package ru.betterend.util;
import net.minecraft.client.color.block.BlockColorProvider;
import net.minecraft.client.color.item.ItemColorProvider;
public interface IColorProvider {
BlockColorProvider getProvider();
ItemColorProvider getItemProvider();
}

View file

@ -0,0 +1,5 @@
{
"variants": {
"": { "model": "betterend:block/aurora_crystal" }
}
}

View file

@ -0,0 +1,6 @@
{
"parent": "betterend:block/tint_cube",
"textures": {
"texture": "betterend:block/aurora_crystal"
}
}

View file

@ -0,0 +1,21 @@
{
"parent": "block/block",
"textures": {
"particle": "#texture"
},
"elements": [
{
"__comment": "Box1",
"from": [ 0, 0, 0 ],
"to": [ 16, 16, 16 ],
"faces": {
"down": { "uv": [ 0, 0, 16, 16 ], "texture": "#texture", "cullface": "down", "tintindex": 0 },
"up": { "uv": [ 0, 0, 16, 16 ], "texture": "#texture", "cullface": "up", "tintindex": 0 },
"north": { "uv": [ 0, 0, 16, 16 ], "texture": "#texture", "cullface": "north", "tintindex": 0 },
"south": { "uv": [ 0, 0, 16, 16 ], "texture": "#texture", "cullface": "south", "tintindex": 0 },
"west": { "uv": [ 0, 0, 16, 16 ], "texture": "#texture", "cullface": "west", "tintindex": 0 },
"east": { "uv": [ 0, 0, 16, 16 ], "texture": "#texture", "cullface": "east", "tintindex": 0 }
}
}
]
}

View file

@ -0,0 +1,3 @@
{
"parent": "betterend:block/aurora_crystal"
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 2 KiB