Skip to content

Commit

Permalink
missing files
Browse files Browse the repository at this point in the history
  • Loading branch information
rotgruengelb committed Jun 17, 2024
1 parent 62ad071 commit 59df8eb
Show file tree
Hide file tree
Showing 11 changed files with 125 additions and 35 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"parent": "block/cube_all",
"parent": "minecraft:block/cube_all",
"textures": {
"all": "sweetofhomes:block/amethyst_bricks"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"parent": "block/cube_all",
"parent": "minecraft:block/cube_all",
"textures": {
"all": "sweetofhomes:block/calcite_bricks"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"parent": "block/cube_all",
"parent": "minecraft:block/cube_all",
"textures": {
"all": "sweetofhomes:block/copper_blitz"
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package net.rotgruengelb.sweetofhomes.datagen;

import net.fabricmc.fabric.api.datagen.v1.DataGeneratorEntrypoint;
import net.fabricmc.fabric.api.datagen.v1.FabricDataGenerator;

public class SweetOfHomesDataGenerator implements DataGeneratorEntrypoint {
@Override
public void onInitializeDataGenerator(FabricDataGenerator fabricDataGenerator) {
FabricDataGenerator.Pack pack = fabricDataGenerator.createPack();

pack.addProvider(ModModelProvider::new);
pack.addProvider(ModLootTableProvider::new);
pack.addProvider(ModItemTagProvider::new);
pack.addProvider(ModBlockTagProvider::new);
pack.addProvider(ModRecipeProvider::new);
pack.addProvider(ModLanguageProvider::new);
}
}
21 changes: 0 additions & 21 deletions src/main/java/net/rotgruengelb/sweetofhomes/item/CopperWrench.java

This file was deleted.

104 changes: 104 additions & 0 deletions src/main/java/net/rotgruengelb/sweetofhomes/item/CopperWrenchItem.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
package net.rotgruengelb.sweetofhomes.item;

import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemUsageContext;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.registry.Registries;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.sound.SoundEvents;
import net.minecraft.stat.Stats;
import net.minecraft.state.StateManager;
import net.minecraft.state.property.Property;
import net.minecraft.text.Text;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.Util;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.WorldAccess;
import net.rotgruengelb.sweetofhomes.world.HomesGameRules;
import org.jetbrains.annotations.Nullable;

import java.util.Collection;

public class CopperWrenchItem extends Item {

public CopperWrenchItem(Settings settings) {
super(settings);
}

private static <T extends Comparable<T>> BlockState cycle(BlockState state, Property<T> property, boolean inverse) {
return state.with(property, CopperWrenchItem.cycle(property.getValues(), state.get(property), inverse));
}

private static <T> T cycle(Iterable<T> elements, @Nullable T current, boolean inverse) {
return inverse ? Util.previous(elements, current) : Util.next(elements, current);
}

private static void sendMessage(PlayerEntity player, Text message) {
if (player.getWorld()
.getGameRules()
.getBoolean(HomesGameRules.SHOW_COPPER_WRENCH_MESSAGES)) {
((ServerPlayerEntity) player).sendMessageToClient(message, true);
}
}

private static <T extends Comparable<T>> String getValueString(BlockState state, Property<T> property) {
return property.name(state.get(property));
}

@Override
public boolean canMine(BlockState state, World world, BlockPos pos, PlayerEntity player) {
if (!world.isClient) {
this.use(player, state, world, pos, false, player.getStackInHand(Hand.MAIN_HAND));
}
return false;
}

@Override
public ActionResult useOnBlock(ItemUsageContext context) {
BlockPos blockPos;
PlayerEntity playerEntity = context.getPlayer();
World world = context.getWorld();
if (!world.isClient && playerEntity != null && !this.use(playerEntity, world.getBlockState(blockPos = context.getBlockPos()), world, blockPos, true, context.getStack())) {
return ActionResult.FAIL;
}
return ActionResult.success(world.isClient);
}

private boolean use(PlayerEntity player, BlockState state, WorldAccess world, BlockPos pos, boolean update, ItemStack stack) {
Block block = state.getBlock();
StateManager<Block, BlockState> stateManager = block.getStateManager();
Collection<Property<?>> collection = stateManager.getProperties();
String string = Registries.BLOCK.getId(block)
.toString();
if (collection.isEmpty()) {
return false;
}
NbtCompound nbtCompound = stack.getOrCreateSubNbt("SelectedProperty");
String string2 = nbtCompound.getString(string);
Property<?> property = stateManager.getProperty(string2);
if (update) {
if (property == null) {
property = collection.iterator()
.next();
}
BlockState blockState = CopperWrenchItem.cycle(state, property, player.shouldCancelInteraction());
world.setBlockState(pos, blockState, Block.NOTIFY_LISTENERS | Block.FORCE_STATE);
player.playSound(SoundEvents.ITEM_SPYGLASS_USE, 1.0f, 1.0f);
player.incrementStat(Stats.USED.getOrCreateStat(this));
CopperWrenchItem.sendMessage(player, Text.translatable(this.getTranslationKey() + ".update", property.getName(), CopperWrenchItem.getValueString(blockState, property)));
} else {
property = CopperWrenchItem.cycle(collection, property, player.shouldCancelInteraction());
String propertyName = property.getName();
nbtCompound.putString(string, propertyName);
CopperWrenchItem.sendMessage(player, Text.translatable(this.getTranslationKey() + ".select", propertyName, CopperWrenchItem.getValueString(state, property)));
}
return true;
}
}

0 comments on commit 59df8eb

Please sign in to comment.