Skip to content

Commit

Permalink
Patched up the Golden Lasso, finished the freezer upgrade's code.
Browse files Browse the repository at this point in the history
  • Loading branch information
Dragonoidzero committed Feb 28, 2021
1 parent d3b86b7 commit 20c20b5
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 13 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ minecraft_version=1.16.5
yarn_mappings=1.16.5+build.5
loader_version=0.11.2
# Mod Properties
mod_version=ALPHA.8
mod_version=ALPHA.9
maven_group=azzy.ttlg
archives_base_name=TTLG
libgui_version=3.3.3+1.16.5
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public void tick() {
tickRecipeProgression();
}
else {
if(trackedRecipe.matches(this, world)) {
if(trackedRecipe.matches(this, world) && trackedRecipe.getType() == getRecipeType()) {
tickRecipeProgression();
if(!getCachedState().get(LIT))
world.setBlockState(pos, getCachedState().with(LIT, true));
Expand Down
23 changes: 18 additions & 5 deletions src/main/java/azzy/fabric/lookingglass/item/GoldenLassoItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@
import net.minecraft.util.registry.Registry;
import net.minecraft.world.World;

import static azzy.fabric.lookingglass.LookingGlassCommon.FFLog;

@SuppressWarnings("rawtypes")
public class GoldenLassoItem extends ToolItem {

public GoldenLassoItem(ToolMaterial toolMaterial, FabricItemSettings goldenLassoSettings) {
super(toolMaterial, goldenLassoSettings);
}
Expand All @@ -36,15 +39,13 @@ public ActionResult useOnBlock(ItemUsageContext context) {
// Spawn the mob above the clicked block position.
BlockPos usedPosition = context.getBlockPos().up();

CompoundTag tmpMobKey = context.getStack().getSubTag("MOB_KEY");
System.out.println(tmpMobKey);

// Don't bother playing on the client side. We live on the server side.
if (genericWorld.isClient)
return ActionResult.PASS;

ServerWorld world = (ServerWorld) genericWorld;
ItemStack itemStack = context.getStack();
FFLog.error(itemStack.getTag());
CompoundTag stackTag = itemStack.getSubTag("MOB_KEY");

if (stackTag == null) {
Expand All @@ -56,7 +57,7 @@ public ActionResult useOnBlock(ItemUsageContext context) {
Identifier mobTypeId = Identifier.tryParse(mobType);
if (mobTypeId == null) {
// Some issue with this mob. Reset the lasso.
LookingGlassCommon.FFLog.warn("Unable to spawn mob: '" + mobType + "'.");
FFLog.warn("Unable to spawn mob: '" + mobType + "'.");
itemStack.removeSubTag("MOB_KEY");
// TODO: Reset the render for the lasso to make it empty again.
return ActionResult.FAIL;
Expand All @@ -69,6 +70,7 @@ public ActionResult useOnBlock(ItemUsageContext context) {
return ActionResult.FAIL;

spawnedEntity.fromTag(mobTag);
itemStack.removeSubTag("MOB_KEY");

return ActionResult.PASS;
}
Expand All @@ -90,7 +92,7 @@ public ActionResult useOnEntity(ItemStack stack, PlayerEntity user, LivingEntity
if (user.getEntityWorld().isClient)
return ActionResult.PASS;

CompoundTag stackTag = stack.getOrCreateSubTag("MOB_KEY");
CompoundTag stackTag = user.getStackInHand(hand).getOrCreateSubTag("MOB_KEY");
CompoundTag mobTag = new CompoundTag();
entity.saveSelfToTag(mobTag);
EntityType entityType = entity.getType();
Expand All @@ -103,4 +105,15 @@ public ActionResult useOnEntity(ItemStack stack, PlayerEntity user, LivingEntity
// TODO: Change the lasso's notification to show the captured mob details (type, health, max health, etc.)
return ActionResult.SUCCESS;
}

/**
* Determines whether or not the lasso should glow, this is determined by whether or not it contains an entity.
*
* @param stack The lasso
* @return Should the lasso shine
*/
@Override
public boolean hasGlint(ItemStack stack) {
return stack.getOrCreateTag().contains("MOB_KEY");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ private static FabricItemSettings eldenmetalSettings() {
public static final Item BASIC_SPEED_UPGRADE = registerGeneratedItem("basic_speed_upgrade", new GenericUpgradeItem(defaultSettings(), 1.2, 0, 0.95, ModifierProvider.AdditivityType.ADD, ModifierProvider.AdditivityType.ADD, LookingGlassMachine.MachineTier.BASIC));
public static final Item BASIC_ENERGY_STORAGE_UPGRADE = registerGeneratedItem("basic_energy_storage_upgrade", new GenericUpgradeItem(defaultSettings(), 1, 0.5, 1, ModifierProvider.AdditivityType.ADD, ModifierProvider.AdditivityType.ADD, LookingGlassMachine.MachineTier.BASIC));
public static final Item BASIC_ENERGY_USAGE_UPGRADE = registerGeneratedItem("basic_energy_usage_upgrade", new GenericUpgradeItem(defaultSettings(), 0.9, 0, 1.05, ModifierProvider.AdditivityType.ADD, ModifierProvider.AdditivityType.ADD, LookingGlassMachine.MachineTier.BASIC));
public static final Item FREEZER_UPGRADE_ITEM = registerGeneratedItem("freezer_upgrade", new RecipeConvertingUpgradeItem<>(defaultSettings(), LookingGlassRecipes.FREEZING_RECIPE, PoweredFurnaceGuiDescription.class, 2.0, 0, 0.5, ModifierProvider.AdditivityType.ADD, ModifierProvider.AdditivityType.ADD));
public static final Item FREEZER_UPGRADE_ITEM = registerGeneratedItem("freezer_upgrade", new RecipeConvertingUpgradeItem<>(defaultSettings(), LookingGlassRecipes.FREEZING_RECIPE, PoweredFurnaceGuiDescription.class, 2.0, 0, 4.0, ModifierProvider.AdditivityType.ADD, ModifierProvider.AdditivityType.ADD));

//Materials
public static final Item FISH_FEED = registerItem("fish_feed", new Item(defaultSettings().food(BAD_NOMS)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
import it.unimi.dsi.fastutil.objects.ReferenceLinkedOpenHashSet;
import me.jellysquid.mods.lithium.common.util.collections.BlockEntityList;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.entity.CommandBlockBlockEntity;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
Expand All @@ -17,9 +19,40 @@
@Mixin(BlockEntityList.class)
public abstract class LithiumBlockEntityListMixin {

@Inject(method = {"addNoDoubleAdd"}, at = {@At("HEAD")}, remap = false)
private void addNoDoubleAdd(BlockEntity blockEntity, boolean exceptionOnDoubleAdd, CallbackInfoReturnable<Boolean> cir) {
exceptionOnDoubleAdd = false;
@Shadow @Final private ReferenceLinkedOpenHashSet<BlockEntity> allBlockEntities;

@Shadow @Final private Long2ReferenceOpenHashMap<BlockEntity> posMap;

@Shadow
private static long getEntityPos(BlockEntity e) {
return 0;
}

@Shadow @Final private Long2ReferenceOpenHashMap<List<BlockEntity>> posMapMulti;

/**
* @author Azazelthedemonlord
* @reason Prevents a crash when moving block entities.
*/
@Overwrite(remap = false)
private boolean addNoDoubleAdd(BlockEntity blockEntity, boolean exceptionOnDoubleAdd) {
boolean added = this.allBlockEntities.add(blockEntity);
if (added && this.posMap != null) {
long pos = getEntityPos(blockEntity);
BlockEntity prev = (BlockEntity)this.posMap.putIfAbsent(pos, blockEntity);
if (prev != null) {
List<BlockEntity> multiEntry = this.posMapMulti.computeIfAbsent(pos, (l) -> {
return new ArrayList<>();
});
if (multiEntry.size() == 0) {
multiEntry.add(prev);
}

multiEntry.add(blockEntity);
}
}

return added;
}

}
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
{
"parent": "lookingglass:block/golden_lasso"
"parent": "item/generated",
"textures": {
"layer0": "lookingglass:item/golden_lasso"
}
}
2 changes: 1 addition & 1 deletion src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"schemaVersion": 1,
"id": "lookingglass",
"version": "2.0.0-alpha.8",
"version": "2.0.0-alpha.9",

"name": "Through The Looking Glass",
"description": "Not a mod about glass working",
Expand Down

0 comments on commit 20c20b5

Please sign in to comment.