-
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.
Add an item group containing sample takers for all entities that have…
… a spawn egg
- Loading branch information
1 parent
d5cbcfa
commit fc9f3b1
Showing
11 changed files
with
100 additions
and
22 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
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
65 changes: 65 additions & 0 deletions
65
src/main/java/top/offsetmonkey538/compactmobfarms/item/FilledSampleTakerItem.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,65 @@ | ||
package top.offsetmonkey538.compactmobfarms.item; | ||
|
||
import java.util.List; | ||
import net.minecraft.client.item.TooltipContext; | ||
import net.minecraft.entity.EntityType; | ||
import net.minecraft.item.Item; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.registry.Registries; | ||
import net.minecraft.text.Text; | ||
import net.minecraft.util.Identifier; | ||
import net.minecraft.world.World; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
public class FilledSampleTakerItem extends Item { | ||
public static final String SAMPLED_ENTITY_KEY = "SampledEntity"; | ||
|
||
public FilledSampleTakerItem(Settings settings) { | ||
super(settings); | ||
} | ||
|
||
@Override | ||
public void appendTooltip(ItemStack stack, @Nullable World world, List<Text> tooltip, TooltipContext context) { | ||
final EntityType<?> sampledEntity = getSampledEntityType(stack); | ||
|
||
if (sampledEntity == null) return; | ||
|
||
tooltip.add(Text.translatable(ModItems.SAMPLE_TAKER.getTranslationKey() + ".tooltip.type", sampledEntity.getName())); | ||
} | ||
|
||
public static void setSampledEntity(ItemStack stack, Identifier entity) { | ||
stack.getOrCreateNbt().putString(SAMPLED_ENTITY_KEY, entity.toString()); | ||
} | ||
|
||
@Nullable | ||
public static Identifier getSampledEntityId(ItemStack stack) { | ||
if (stack.getNbt() == null || !stack.getNbt().contains(SAMPLED_ENTITY_KEY)) return null; | ||
return new Identifier(stack.getNbt().getString(SAMPLED_ENTITY_KEY)); | ||
} | ||
|
||
@Nullable | ||
public static EntityType<?> getSampledEntityType(ItemStack stack) { | ||
final Identifier id = getSampledEntityId(stack); | ||
|
||
if (id == null || !Registries.ENTITY_TYPE.containsId(id)) return null; | ||
|
||
return Registries.ENTITY_TYPE.get(id); | ||
} | ||
|
||
public ItemStack forEntity(@Nullable EntityType<?> entity) { | ||
return forEntity(Registries.ENTITY_TYPE.getId(entity)); | ||
} | ||
|
||
public ItemStack forEntity(Identifier entityId) { | ||
final ItemStack stack = new ItemStack(this); | ||
|
||
setSampledEntity(stack, entityId); | ||
|
||
return stack; | ||
} | ||
|
||
@Override | ||
public ItemStack getDefaultStack() { | ||
return forEntity(Registries.ENTITY_TYPE.getDefaultId()); | ||
} | ||
} |
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
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
File renamed without changes