-
Notifications
You must be signed in to change notification settings - Fork 0
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
62ad071
commit 59df8eb
Showing
11 changed files
with
125 additions
and
35 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
...ofhomes/models/block/amethyst_bricks.json → ...ofhomes/models/block/amethyst_bricks.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
2 changes: 1 addition & 1 deletion
2
...tofhomes/models/block/calcite_bricks.json → ...tofhomes/models/block/calcite_bricks.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
2 changes: 1 addition & 1 deletion
2
...eetofhomes/models/block/copper_blitz.json → ...eetofhomes/models/block/copper_blitz.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
11 changes: 0 additions & 11 deletions
11
src/main/java/net/rotgruengelb/sweetofhomes/SweetOfHomesDataGenerator.java
This file was deleted.
Oops, something went wrong.
18 changes: 18 additions & 0 deletions
18
src/main/java/net/rotgruengelb/sweetofhomes/datagen/SweetOfHomesDataGenerator.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,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
21
src/main/java/net/rotgruengelb/sweetofhomes/item/CopperWrench.java
This file was deleted.
Oops, something went wrong.
104 changes: 104 additions & 0 deletions
104
src/main/java/net/rotgruengelb/sweetofhomes/item/CopperWrenchItem.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,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; | ||
} | ||
} | ||
|