Skip to content

Commit

Permalink
Chameleon??
Browse files Browse the repository at this point in the history
  • Loading branch information
N1nn1 committed Aug 23, 2024
1 parent 902a22a commit 10bcba9
Show file tree
Hide file tree
Showing 21 changed files with 180 additions and 31 deletions.
10 changes: 5 additions & 5 deletions src/main/java/com/ninni/spawn/client/model/HerringModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,11 @@ public void setupAnim(T entity, float limbAngle, float limbDistance, float anima



this.root.y = Mth.cos(animationProgress + 3) * 0.4F * 0.25F;
this.root.yRot = Mth.cos(animationProgress + 1) * 0.4F * 0.25F;
this.tail.yRot = Mth.cos(animationProgress + 2) * 2.8F * 0.25F;
this.rightFin.zRot = Mth.cos(animationProgress + 1f + pi) * 2 * 0.25F + 0.6F;
this.leftFin.zRot = Mth.cos(animationProgress + 1.5f) * 2F * 0.25F - 0.6F;
this.root.y = Mth.cos(animationProgress * 0.5f + 3) * 0.4F * 0.25F;
this.root.yRot = Mth.cos(animationProgress * 0.5f + 1) * 0.4F * 0.25F;
this.tail.yRot = Mth.cos(animationProgress * 0.5f + 2) * 2.8F * 0.25F;
this.rightFin.zRot = Mth.cos(animationProgress * 0.5f + 1f + pi) * 2 * 0.25F + 0.6F;
this.leftFin.zRot = Mth.cos(animationProgress * 0.5f + 1.5f) * 2F * 0.25F - 0.6F;
}
}

33 changes: 31 additions & 2 deletions src/main/java/com/ninni/spawn/item/ChameleonShedBlockItem.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
package com.ninni.spawn.item;

import com.ninni.spawn.block.entity.ChameleonShedBlockEntity;
import com.ninni.spawn.entity.Octopus;
import net.minecraft.ChatFormatting;
import net.minecraft.core.BlockPos;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.Style;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.DyeableLeatherItem;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.TooltipFlag;
import net.minecraft.world.item.context.UseOnContext;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
Expand All @@ -17,11 +22,37 @@
import net.minecraft.world.level.block.state.BlockState;
import org.jetbrains.annotations.Nullable;

import java.util.List;

public class ChameleonShedBlockItem extends BlockItem implements DyeableLeatherItem {
public ChameleonShedBlockItem(Block block, Properties properties) {
super(block, properties);
}

public void appendHoverText(ItemStack itemStack, @Nullable Level level, List<Component> list, TooltipFlag tooltipFlag) {
ChatFormatting[] chatFormattings = new ChatFormatting[]{ChatFormatting.GRAY};
CompoundTag compoundTag = itemStack.getTagElement("BlockEntityTag");

if (compoundTag != null && compoundTag.contains("color", 99) && compoundTag.getInt("color") != 0xFFFFFF) {
int rem;
int decimal = compoundTag.getInt("color");
StringBuilder hex= new StringBuilder();
char[] hexchars ={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
while(decimal>0)
{
rem=decimal%16;
hex.insert(0, hexchars[rem]);
decimal=decimal/16;
}

list.add(
Component.translatable("item.spawn.chameleon_shed.color").withStyle(chatFormattings)
.append(Component.translatable("#" + hex).withStyle(Style.EMPTY.withColor(compoundTag.getInt("color"))))
);
}
super.appendHoverText(itemStack, level, list, tooltipFlag);
}

public boolean hasCustomColor(ItemStack itemStack) {
CompoundTag compoundTag = itemStack.getTagElement("BlockEntityTag");
return compoundTag != null && compoundTag.contains("color", 99) && compoundTag.getInt("color") != 0xFFFFFF;
Expand All @@ -47,8 +78,6 @@ public InteractionResult useOn(UseOnContext useOnContext) {
BlockState state = useOnContext.getLevel().getBlockState(blockPos);
ItemStack itemStack = useOnContext.getPlayer().getItemInHand(useOnContext.getHand());

System.out.println("hi");

if (state.is(Blocks.WATER_CAULDRON) && this.hasCustomColor(itemStack)) {
ItemStack itemStack2 = itemStack.copy();
this.clearColor(itemStack2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ public class SpawnBlockEntityTypes {
BuiltInRegistries.BLOCK_ENTITY_TYPE,
new ResourceLocation(Spawn.MOD_ID, "chameleon_shed_block"),
BlockEntityType.Builder.of(ChameleonShedBlockEntity::new,
SpawnBlocks.CHAMELEON_SHED_BLOCK
SpawnBlocks.CHAMELEON_SHED_BLOCK,
SpawnBlocks.CHAMELEON_SHED_PLATES,
SpawnBlocks.CHAMELEON_SHED_SCALES
).build(null)
);
}
4 changes: 3 additions & 1 deletion src/main/java/com/ninni/spawn/registry/SpawnBlocks.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ public class SpawnBlocks {
public static final Block WHALE_UVULA = register("whale_uvula", new WhaleUvulaBlock(FabricBlockSettings.copyOf(WHALE_FLESH).lightLevel((blockStatex) -> 15)));

// chameleon
public static final Block CHAMELEON_SHED_BLOCK = register("chameleon_shed_block", new ChameleonShedBlock(FabricBlockSettings.create()));
public static final Block CHAMELEON_SHED_BLOCK = register("chameleon_shed_block", new ChameleonShedBlock(FabricBlockSettings.create().strength(0.1f).sound(SoundType.MOSS)));
public static final Block CHAMELEON_SHED_PLATES = register("chameleon_shed_plates", new ChameleonShedBlock(FabricBlockSettings.create().strength(0.2f).sound(SoundType.MOSS)));
public static final Block CHAMELEON_SHED_SCALES = register("chameleon_shed_scales", new ChameleonShedBlock(FabricBlockSettings.create().strength(0.2f).sound(SoundType.MOSS)));


private static Block register(String id, Block block) {
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/ninni/spawn/registry/SpawnItems.java
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ public class SpawnItems {
// chameleon
public static final Item CHAMELEON_SHED = register("chameleon_shed", new Item(new FabricItemSettings()));
public static final Item CHAMELEON_SHED_BLOCK = register("chameleon_shed_block", new ChameleonShedBlockItem(SpawnBlocks.CHAMELEON_SHED_BLOCK, new FabricItemSettings()));
public static final Item CHAMELEON_SHED_PLATES = register("chameleon_shed_plates", new ChameleonShedBlockItem(SpawnBlocks.CHAMELEON_SHED_PLATES, new FabricItemSettings()));
public static final Item CHAMELEON_SHED_SCALES = register("chameleon_shed_scales", new ChameleonShedBlockItem(SpawnBlocks.CHAMELEON_SHED_SCALES, new FabricItemSettings()));

private static Item register(String id, Item item) {
return Registry.register(BuiltInRegistries.ITEM, new ResourceLocation(Spawn.MOD_ID, id), item);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,11 @@ private static void registerItemModelPredicates() {

ColorProviderRegistry.ITEM.register((itemStack, i) -> i > 0 ? -1 : ((ClamCaseItem) itemStack.getItem()).getColor(itemStack), SpawnItems.CLAM_CASE);

ColorProviderRegistry.ITEM.register((itemStack, i) -> ((ChameleonShedBlockItem) itemStack.getItem()).getColor(itemStack), SpawnItems.CHAMELEON_SHED_BLOCK);
ColorProviderRegistry.ITEM.register((itemStack, i) -> ((ChameleonShedBlockItem) itemStack.getItem()).getColor(itemStack),
SpawnItems.CHAMELEON_SHED_BLOCK,
SpawnItems.CHAMELEON_SHED_PLATES,
SpawnItems.CHAMELEON_SHED_SCALES
);

}

Expand All @@ -220,7 +224,9 @@ private static void registerBlockTints() {
}
return 0xFFFFFF;
},
SpawnBlocks.CHAMELEON_SHED_BLOCK
SpawnBlocks.CHAMELEON_SHED_BLOCK,
SpawnBlocks.CHAMELEON_SHED_PLATES,
SpawnBlocks.CHAMELEON_SHED_SCALES
);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"variants": {
"": {
"model": "spawn:block/chameleon_shed_plates"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"variants": {
"": {
"model": "spawn:block/chameleon_shed_scales"
}
}
}
8 changes: 7 additions & 1 deletion src/main/resources/assets/spawn/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -216,5 +216,11 @@
"item.spawn.sunfish_spawn_egg": "Sunfish Spawn Egg",
"item.spawn.baby_sunfish_bucket": "Bucket of Baby Sunfish",
"advancements.spawn.breed_sunfish.title": "Baby Boom!",
"advancements.spawn.breed_sunfish.description": "Breed two Sunfish together"
"advancements.spawn.breed_sunfish.description": "Breed two Sunfish together",

"item.spawn.chameleon_shed": "Chameleon Shed",
"item.spawn.chameleon_shed.color": "Color: ",
"block.spawn.chameleon_shed_block": "Chameleon Shed Block",
"block.spawn.chameleon_shed_plates": "Chameleon Shed Plates",
"block.spawn.chameleon_shed_scales": "Chameleon Shed Scales"
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,6 @@
{
"parent": "block/block",
"parent": "spawn:block/template_chameleon_cube_all",
"textures": {
"all": "spawn:block/chameleon_shed_block",
"particle": "#all"
},
"elements": [
{ "from": [ 0, 0, 0 ],
"to": [ 16, 16, 16 ],
"faces": {
"down": { "texture": "#all", "cullface": "down", "tintindex": 0 },
"up": { "texture": "#all", "cullface": "up", "tintindex": 0 },
"north": { "texture": "#all", "cullface": "north", "tintindex": 0 },
"south": { "texture": "#all", "cullface": "south", "tintindex": 0 },
"west": { "texture": "#all", "cullface": "west", "tintindex": 0 },
"east": { "texture": "#all", "cullface": "east", "tintindex": 0 }
}
}
]
"all": "spawn:block/chameleon_shed_block"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"parent": "spawn:block/template_chameleon_cube_all",
"textures": {
"all": "spawn:block/chameleon_shed_plates"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"parent": "spawn:block/template_chameleon_cube_all",
"textures": {
"all": "spawn:block/chameleon_shed_scales"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"parent": "block/block",
"textures": {
"particle": "#all"
},
"elements": [
{ "from": [ 0, 0, 0 ],
"to": [ 16, 16, 16 ],
"faces": {
"down": { "texture": "#all", "cullface": "down", "tintindex": 0 },
"up": { "texture": "#all", "cullface": "up", "tintindex": 0 },
"north": { "texture": "#all", "cullface": "north", "tintindex": 0 },
"south": { "texture": "#all", "cullface": "south", "tintindex": 0 },
"west": { "texture": "#all", "cullface": "west", "tintindex": 0 },
"east": { "texture": "#all", "cullface": "east", "tintindex": 0 }
}
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"parent": "spawn:block/chameleon_shed_plates"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"parent": "spawn:block/chameleon_shed_scales"
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"replace": false,
"values": [
"spawn:chameleon_shed_block",
"spawn:chameleon_shed_scales",
"spawn:chameleon_shed_plates"
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
"spawn:snail_shell_tile_stairs",
"spawn:snail_shell_tile_slab",
"spawn:pigment_shifter",
"spawn:clam_launcher",
"spawn:chameleon_shed_block"
"spawn:clam_launcher"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"type": "minecraft:block",
"pools": [
{
"bonus_rolls": 0.0,
"entries": [
{
"type": "minecraft:item",
"functions": [
{
"function": "minecraft:copy_nbt",
"ops": [
{
"op": "replace",
"source": "color",
"target": "BlockEntityTag.color"
}
],
"source": "block_entity"
}
],
"name": "spawn:chameleon_shed_plates"
}
],
"rolls": 1.0
}
],
"random_sequence": "spawn:blocks/chameleon_shed_plates"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"type": "minecraft:block",
"pools": [
{
"bonus_rolls": 0.0,
"entries": [
{
"type": "minecraft:item",
"functions": [
{
"function": "minecraft:copy_nbt",
"ops": [
{
"op": "replace",
"source": "color",
"target": "BlockEntityTag.color"
}
],
"source": "block_entity"
}
],
"name": "spawn:chameleon_shed_scales"
}
],
"rolls": 1.0
}
],
"random_sequence": "spawn:blocks/chameleon_shed_scales"
}

0 comments on commit 10bcba9

Please sign in to comment.